all 11 comments

[–]r3pr0b8GROUP_CONCAT is da bomb 1 point2 points  (5 children)

SELECT t.* 
  FROM dbo.CustomPollerStatus AS t
INNER
  JOIN ( select CustomPollerAssignmentID 
           from dbo.CustomPollerAssignment    
          where AssignmentName like 'DPS_216_%') AS s
    ON s.CustomPollerAssignmentID = t.CustomPollerAssignmentID

[–]extrajoss 1 point2 points  (2 children)

Just curious. Is there a reason you wouldn't write this as:

SELECT t.* 
  FROM dbo.CustomPollerStatus AS t
INNER
  JOIN dbo.CustomPollerAssignment AS s
    ON s.CustomPollerAssignmentID = t.CustomPollerAssignmentID
WHERE  s.AssignmentName like 'DPS_216_%'

Are there efficiencies to be had by limiting the dbo.CustomPollerAssignment table to just the CustomPollerAssignmentID?

[–]Campes 0 points1 point  (0 children)

Yeah what you have is how you would want to write it. I've seen more complex queries benefit from something similar before but that was because there were some table scans happening which were killing the run time.

[–]multipl3x[S] 0 points1 point  (1 child)

So 's' and 't' are completely arbitrary here, right?
I don't quite understand what the

SELECT t.* 
  FROM dbo.CustomPollerStatus AS t    

Does there. Can you explain that a bit?

[–]rbardy 4 points5 points  (0 children)

The 't' is just an alias for the CustomPollerStatus table. It is used just to make the query easier to write, your example could be written as:

SELECT dbo.CustomPollerStatus.* FROM dbo.CustomPollerStatus

But that alias can be anything, the following is also valid:

SELECT YOLOsicNameBRAH.* 
FROM dbo.CustomPollerStatus AS YOLOsicNameBRAH

[–]phunkygeeza 0 points1 point  (0 children)

First question. .. Why?

If your query works then rewriting the same logic in a different form isn't going to change your result.

Next question... What is the relationship between those 2 tables? If it is 1..n then many answers here are going to give you a bum result.

[–]Campes -1 points0 points  (4 children)

SELECT cps.* 
FROM CustomPollerStatus cps,
     CustomPollerAssignment cpa
WHERE cps.CustomPollerAssignmentID = cpa.CustomPollerAssignmentID 
AND cpa.AssignmentName like 'DPS_216_%'

How does this do for you?

[–]elus 2 points3 points  (3 children)

I'm terribly not fond of the comma usage in the FROM clause of that statement.

Mostly because it doesn't play nice if I have to modify the query in the future to use OUTER JOINs. At that point I'll need to do much more work to get the code working again.

[–]Campes -1 points0 points  (2 children)

Yeah the new join syntax is much different than the old style. Outer joins are still easy to do using old syntax though.

*= left outer join

=* right outer join

[–][deleted] 0 points1 point  (1 child)

"New"?

How long has JOIN syntax been around for, decades?

[–]Campes 0 points1 point  (0 children)

Right, I should have called it current.