SirChick Posted November 12, 2007 Share Posted November 12, 2007 I am wondering if something like this can be done: SELECT userid from userstable Then check a table named Hospital... for userid Then what i need to do is a while loop which will "only" while loop through users that are not in the hospital table but are in the user table..... meaning only people out of hospital will be queried but "all" out of hospital users must be ran through the while loop.. is this possible in one query? Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 12, 2007 Share Posted November 12, 2007 You only need 1 query. Using a loop for queries is extremely inefficient and can create performance issues. The following query should return all users that exist in the user table which do not have any associated records in the hospital table. SELECT u.* FROM userstable u LEFT JOIN hospitals h ON u.userid = h.userid WHERE h.AnyColumInHospitalTable = NULL Quote Link to comment Share on other sites More sharing options...
SirChick Posted November 12, 2007 Author Share Posted November 12, 2007 I tried this : $Get = mysql_query("SELECT u.* FROM userregistration u LEFT JOIN hospital h ON u.UserID = h.UserID WHERE h.IllnessType = NULL") or die (mysql_error()); while(mysql_fetch_assoc($Get)){ echo 'test'; } but it didn't work =/ It should have done 4 echo's for 'test' Quote Link to comment Share on other sites More sharing options...
Branden Wagner Posted November 12, 2007 Share Posted November 12, 2007 What did it do? did you get an error? Quote Link to comment Share on other sites More sharing options...
SirChick Posted November 12, 2007 Author Share Posted November 12, 2007 no it didnt echo basically.... just a blank screen Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 12, 2007 Share Posted November 12, 2007 OK, try changing the "= NULL" to "IS NULL". I have tested it and it works for me. Quote Link to comment 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.