Thread: Help with Query
View Single Post
Old 09-18-2012, 10:45 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,237
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
No, a UNION is *NO HELP* for this situation. Period.

Why did you not try my query?

Anyway, you never mentioned that another table was involved.

But that just means you need to extend the concept of my query.
Code:
SELECT m1.Alias,
       m1.Week, n1.TeamID, n1.Name,
       m2.Week, n2.TeamID, n2.Name
FROM margin AS m1, margin AS m2, nflteams as n1, nflteams AS n2
WHERE m1.Alias = m2.Alias
AND m1.week = 1
AND m1.PickID = n1.TeamID
AND m2.week = 2
AND m2.PickID = n2.TeamID
ORDER BY m1.Alias
And *PLEASE* don't put apostrophes around NUMBERS! (as you did with m.Week='1')
MySQL is sloppy enough to allow it in non-strict mode, but it is a BAD HABIT to get into.
Treat numbers as numbers and strings as strings.

And there is no reason to SELECT both PickID and TeamID since the conditions of your WHERE clause *guarantee* that they will be the same!
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

Last edited by Old Pedant; 09-18-2012 at 10:47 PM..
Old Pedant is offline   Reply With Quote