will35010 Posted December 1, 2009 Share Posted December 1, 2009 Why is this query returning lots of extra data? How do I fix this? SELECT lobby.MRN, pt_status.PATIENT_LAST_NAME, pt_status.PATIENT_FIRST_NAME, pt_status.AGE, pt_status.SEX, pt_status.CC, pt_status.CURRENT_LOCATION, pt_status.CURRENT_STATUS, pt_status.REG_TIME FROM lobby, pt_status WHERE lobby.MRN = pt_status.MRN OR pt_status.CURRENT_STATUS = 'Ready to Triage' It's returning this: 1259697523 Chesterfield Douglas 54 Male Chest Pain Lobby Waiting on Room 1259697523 1259701307 Weaver Linda 20 Female psycho Lobby Waiting on Room 1259701307 1259697523 Harris Tate 32 Male Head Injury ER Ready to Triage 1259710317 1259701307 Harris Tate 32 Male Head Injury ER Ready to Triage 1259710317 1259710500 Harris Tate 32 Male Head Injury ER Ready to Triage 1259710317 1259697523 Morris Will 27 Male Nausea/Vomiting Lobby Ready to Triage 1259710500 1259701307 Morris Will 27 Male Nausea/Vomiting Lobby Ready to Triage 1259710500 1259710500 Morris Will 27 Male Nausea/Vomiting Lobby Ready to Triage 1259710500 Quote Link to comment https://forums.phpfreaks.com/topic/183658-mysql-query-problem/ Share on other sites More sharing options...
rajivgonsalves Posted December 1, 2009 Share Posted December 1, 2009 Change your "OR" to "AND" Quote Link to comment https://forums.phpfreaks.com/topic/183658-mysql-query-problem/#findComment-969375 Share on other sites More sharing options...
will35010 Posted December 1, 2009 Author Share Posted December 1, 2009 Change your "OR" to "AND" I want it to pull the data if either of those conditions are true. Not if both are true. Quote Link to comment https://forums.phpfreaks.com/topic/183658-mysql-query-problem/#findComment-969377 Share on other sites More sharing options...
rajivgonsalves Posted December 1, 2009 Share Posted December 1, 2009 hmmm.. what is the common column between these two tables ? Quote Link to comment https://forums.phpfreaks.com/topic/183658-mysql-query-problem/#findComment-969381 Share on other sites More sharing options...
will35010 Posted December 2, 2009 Author Share Posted December 2, 2009 hmmm.. what is the common column between these two tables ? I've attached my db schema. The only patients that are stored in the lobby table are patients that are physically there. If we do a direct admit to room they won't be in the lobby table but their current status on the pt_status will be ready to triage. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/183658-mysql-query-problem/#findComment-969387 Share on other sites More sharing options...
rajivgonsalves Posted December 2, 2009 Share Posted December 2, 2009 from seeing your db structure I cannot tell you how the tables are related to each other, thats something you will have to tell me Quote Link to comment https://forums.phpfreaks.com/topic/183658-mysql-query-problem/#findComment-969391 Share on other sites More sharing options...
will35010 Posted December 2, 2009 Author Share Posted December 2, 2009 from seeing your db structure I cannot tell you how the tables are related to each other, thats something you will have to tell me Thanks for your help. I'm just gonna simplify it and run two queries in my code. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/183658-mysql-query-problem/#findComment-969393 Share on other sites More sharing options...
fenway Posted December 4, 2009 Share Posted December 4, 2009 That's the less optimal solution, through. Quote Link to comment https://forums.phpfreaks.com/topic/183658-mysql-query-problem/#findComment-971237 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.