will35010 Posted February 2, 2011 Share Posted February 2, 2011 I have a query that works fine except it won't let me limit the results. Current Query: SELECT rooms.room, visit_data.patientid, visit_data.priority, visit_data.alert1, visit_data.alert2, visit_data.alert3, visit_data.areaid, visit_data.doctor, visit_data.nurse, visit_data.cc, visit_data.current_status, visit_data.reg_time FROM rooms LEFT JOIN visit_data ON rooms.room = visit_data.room AND visit_data.areaid = 'ED' Both tables have an areaid (example: rooms.areaid, visit_data.areaid) I only want to pull data for a specific areaid, but no matter what areaid I put in it returns the same results with all areas like the AND clause isn't even there. How do I fix my query? I tried changing and to WHERE, but then it didn't return all the results I wanted from the left table. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/226483-left-join-where-problem/ Share on other sites More sharing options...
mikosiko Posted February 2, 2011 Share Posted February 2, 2011 did you try: .... FROM rooms LEFT JOIN visit_data ON rooms.room = visit_data.room AND visit_data.areaid = 'ED' WHERE rooms.areaid = 'ED' Quote Link to comment https://forums.phpfreaks.com/topic/226483-left-join-where-problem/#findComment-1169003 Share on other sites More sharing options...
will35010 Posted February 2, 2011 Author Share Posted February 2, 2011 did you try: .... FROM rooms LEFT JOIN visit_data ON rooms.room = visit_data.room AND visit_data.areaid = 'ED' WHERE rooms.areaid = 'ED' That worked perfectly. Thank you!!! Quote Link to comment https://forums.phpfreaks.com/topic/226483-left-join-where-problem/#findComment-1169006 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.