boonamera Posted July 29, 2006 Share Posted July 29, 2006 table 1 (users)userid usernametable 2(payments)paymentiduseridI need two thingsUSERIDS of those who PAID. This works:SELECT u.userid FROM users u JOIN payments ON u.userid = payments.userid;USERIDS of those who haven't paid. This is my problemI tried something along the lines of: but no luckSELECT u.userid FROM users u LEFT JOIN payments ON u.userid = payments.userid LIMIT 99999 OFFSET ("SELECT ( (SELECT COUNT(*) FROM users)-(SELECT COUNT(*) FROM payments) ));but no luckanyone have an idea? Quote Link to comment https://forums.phpfreaks.com/topic/15963-inversing-a-selection-when-joining-tables/ Share on other sites More sharing options...
shoz Posted July 29, 2006 Share Posted July 29, 2006 If people who haven't paid don't have an entry in the payments table, then the following should work.[code]SELECTu.useridFROMusers AS uLEFT JOINpaymentsONu.userid = payments.useridWHEREpayments.userid IS NULL[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15963-inversing-a-selection-when-joining-tables/#findComment-65578 Share on other sites More sharing options...
fenway Posted July 29, 2006 Share Posted July 29, 2006 Yeah, go with shoz's suggestion... I nearly fell of my chair when I saw those crazy subselects with that LIMIT clause. ;-) Quote Link to comment https://forums.phpfreaks.com/topic/15963-inversing-a-selection-when-joining-tables/#findComment-65584 Share on other sites More sharing options...
boonamera Posted July 29, 2006 Author Share Posted July 29, 2006 AWESOME IT WORKEDthanks shoz lol hey I used the minimal knowledge to try and get it working :) Quote Link to comment https://forums.phpfreaks.com/topic/15963-inversing-a-selection-when-joining-tables/#findComment-65588 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.