Click to See Complete Forum and Search --> : issue with query (mysql 5.0)


ixxalnxxi
06-12-2008, 07:48 PM
the following query works except when the UserComments contains no rows with the StationID. any idea how to return just the Station info in that case?

SELECT s.*, AVG(uc.Rating) AS Rating
FROM Stations s, UserComments uc
WHERE s.StationID = 4
AND s.StationID = uc.StationID
GROUP BY uc.StationID

legendx
06-13-2008, 09:22 AM
Left Join:


SELECT s.*, AVG(uc.Rating) AS Rating
FROM Stations s LEFT JOIN UserComments uc ON s.StationID = uc.StationID
WHERE s.StationID = 4
GROUP BY uc.StationID


Also, you will probably have to GROUP BY all the fields in s.* for this to work properly.

ixxalnxxi
06-22-2008, 11:49 PM
omg legendx U R SO SMART LOL.

that helped a bunch, i'm completely unfamiliar with any JOIN, have to read up on that ~ thanks again.