I have two table – report and bouydata
report
------
id sun
1 overcast
bouydata
----------
reportid bouy winddir
1 46026 340
1 46027 345
I want to select all 3 rows into one row. Here’s my query:
SELECT report.id, sun, bouy1.bouy as bouy1, bouy1.winddir as winddir1, bouy2.bouy as bouy2, bouy2.winddir as winddir2
FROM report
LEFT JOIN bouydata bouy1
ON report.id = bouy1.reportid
LEFT JOIN bouydata bouy2
ON report.id = bouy2.reportid
For some reason I’m getting four rows back:
1 Slightly Overcast 46026 340 46026 340
1 Slightly Overcast 46026 340 46027 345
1 Slightly Overcast 46027 345 46026 340
1 Slightly Overcast 46027 345 46027 345
It’s not selecting only the unique rows and combining them into one row. Can anyone help me get my desired result of:
1 Slightly Overcast 46026 340 46027 345
I don’t know why you’re doing a double-join, with the same tables and same conditions. That just duplicates information.
would give you: