![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi there, this statement works fine but I'm wondering is there any way to simplify it? SELECT score, (SELECT name from players WHERE playerID=records.playerID LIMIT 1) as playername, (SELECT name from teams WHERE teamID=records.teamID LIMIT 1) as teamname FROM records Thanks for any help! Ciarán |
#3
| |||
| |||
|
|
On 12 May, 13:54, Ciaran <cronok... (AT) hotmail (DOT) com> wrote: Hi there, this statement works fine but I'm wondering is there any way to simplify it? SELECT score, (SELECT name from players WHERE playerID=records.playerID LIMIT 1) as playername, (SELECT name from teams WHERE teamID=records.teamID LIMIT 1) as teamname FROM records Thanks for any help! Ciarán SELECT r.score, p.name, t.name FROM records r LEFT JOIN players p ON p.playerid = r.playerid LEFT JOIN teams ON t.team_id = r.team_id; I'm not sure what all that "LIMIT 1" stuff is supposed to do in this context! |
#4
| |||
| |||
|
|
On May 12, 3:35 pm, strawberry <zac.ca... (AT) gmail (DOT) com> wrote: On 12 May, 13:54, Ciaran <cronok... (AT) hotmail (DOT) com> wrote: Hi there, this statement works fine but I'm wondering is there any way to simplify it? SELECT score, (SELECT name from players WHERE playerID=records.playerID LIMIT 1) as playername, (SELECT name from teams WHERE teamID=records.teamID LIMIT 1) as teamname FROM records Thanks for any help! Ciarán SELECT r.score, p.name, t.name FROM records r LEFT JOIN players p ON p.playerid = r.playerid LEFT JOIN teams ON t.team_id = r.team_id; I'm not sure what all that "LIMIT 1" stuff is supposed to do in this context! Thanks Strawberry, I'll have to read up on left joins! I assumed adding LIMIT 1 would stop the query from searching after it had found 1 match, making it a little quicker, but I suspect I might be mistaken? |
![]() |
| Thread Tools | |
| Display Modes | |
| |