tags:

views:

52

answers:

2
+1  A: 

If there are two players with the same surnames that were playing in the different teams they will merge in the first query but not the second:

bat1   bat2   team
Smith  Jones  UK
Doe    Smith  Zealand

The first query will return Smith once, the second one twice.

It is most probable that your first query is wrong, not the second one. Try running this for your first query:

SELECT  batname
FROM    (
        SELECT  bat1Name AS batname, team
        FROM   details
        UNION
        SELECT  bat2Name, team
        FROM   details
        UNION  …
        ) q

You don't need to do DISTINCT here: UNION will take care of this automatically.

Quassnoi
Thank you very much for the response, that makes sense!
Theresa
I have posted another query if you wouldn't mind helping :)http://stackoverflow.com/questions/2348427/mysql-how-to-find-player-id-from-surname
Theresa
A: 

As Quassnoi says it is probably the first query that is wrong as the second one will pull out the right data.

Also the player table should only store the player related data with a relation to another table storing the teams.

Richard Harrison
Thanks, I have it referencing a 'team' table.I have posted another query if you wouldn't mind helping :)http://stackoverflow.com/questions/2348427/mysql-how-to-find-player-id-from-surname
Theresa