otuatail Posted November 4, 2009 Share Posted November 4, 2009 Can someone tell me how to extract records that I need for a mailing list. The first 3 are easy the last I can’t work out. I need to recover any records that have dropped out of the system because of an invalid entry Select * from Customers where Age < 21; Select * from Customers where UK = true; Select * from Customers where Special_Delivery = true ; There could be a lot of queries. I need one that recovers all the remaining like Select * from Customers where where ..... Not covered by SQL1 ,SQL2 , SQL3 It would mean adding queries together. TIA Desmond. Quote Link to comment https://forums.phpfreaks.com/topic/180274-solved-joining-sqls-together/ Share on other sites More sharing options...
Mchl Posted November 4, 2009 Share Posted November 4, 2009 SELECT * FROM Customers WHERE Age <= 21 OR UK != true OR Special_Delivery != true Quote Link to comment https://forums.phpfreaks.com/topic/180274-solved-joining-sqls-together/#findComment-950972 Share on other sites More sharing options...
otuatail Posted November 4, 2009 Author Share Posted November 4, 2009 Yes this would work but I might have to extend it. I thought I could copy a query inside another query. I have seen queries before with multipul SELECT statments in them like WHERE (SELECT * FROM ...) The above could get very messy! Quote Link to comment https://forums.phpfreaks.com/topic/180274-solved-joining-sqls-together/#findComment-950978 Share on other sites More sharing options...
shlumph Posted November 4, 2009 Share Posted November 4, 2009 SELECT * FROM Customers WHERE Age >= 21 AND UK != true AND Special_Delivery != true However, I thought that boolean wasn't a valid SQL data type? What DB are you using? Quote Link to comment https://forums.phpfreaks.com/topic/180274-solved-joining-sqls-together/#findComment-950992 Share on other sites More sharing options...
Mchl Posted November 4, 2009 Share Posted November 4, 2009 However, I thought that boolean wasn't a valid SQL data type? It is not and it is at one time SELECT true = 1, false = 0 Quote Link to comment https://forums.phpfreaks.com/topic/180274-solved-joining-sqls-together/#findComment-950993 Share on other sites More sharing options...
Mchl Posted November 4, 2009 Share Posted November 4, 2009 Yes this would work but I might have to extend it. I thought I could copy a query inside another query. I have seen queries before with multipul SELECT statments in them like WHERE (SELECT * FROM ...) The above could get very messy! I don't think so. Using subqueries for such simple task would actually be even more messy WHERE Customers.ID NOT IN (SELECT ID FROM Customers WHERE Age < 21) OR Customers.ID NOT IN (SELECT ID FROM Customers WHERE UK = true) OR Customers.ID NOT IN (SELECT ID FROM Customers WHERE Special_Delivery = true) Quote Link to comment https://forums.phpfreaks.com/topic/180274-solved-joining-sqls-together/#findComment-950997 Share on other sites More sharing options...
otuatail Posted November 4, 2009 Author Share Posted November 4, 2009 Thanks alot that is what I was after. Desmond. Quote Link to comment https://forums.phpfreaks.com/topic/180274-solved-joining-sqls-together/#findComment-951008 Share on other sites More sharing options...
Mchl Posted November 4, 2009 Share Posted November 4, 2009 If it suits you... It will be slower however (it runs four queries instead of one) Quote Link to comment https://forums.phpfreaks.com/topic/180274-solved-joining-sqls-together/#findComment-951010 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.