Jump to content

inversing a selection when joining tables


boonamera

Recommended Posts

table 1 (users)
userid
username

table 2(payments)
paymentid
userid

I need two things
USERIDS 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 problem
I tried something along the lines of: but no luck
SELECT 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 luck

anyone have an idea?

Link to comment
Share on other sites

If people who haven't paid don't have an entry in the payments table, then the following should work.
[code]
SELECT
u.userid
FROM
users AS u
LEFT JOIN
payments
ON
u.userid = payments.userid
WHERE
payments.userid IS NULL
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.