Jump to content

Select using <> on Join


Darkness Soul

Recommended Posts

Yo, :)

I'm with a little problem. I have two tables, tbUsers and tbMail. When I send a mail to my users (like newsletter sys), I record the Mail id and the User id into tbAux.

But, we have lots of users, and our server can't send it all at once, our script works like it:

select 200 users who are not at the tbAux, send, wait a little time, reexecute.

This select is my problem.. It return all the users in or not in tbAux.. :(

My select string:

[code]SELECT
    DISTINCT
    tbUser.id ,
    tbUser.name ,
    tbUser.email
FROM
    tbUser
INNER JOIN
    tbAux
ON
    tbAux.id_user <> tbUser.id
WHERE
    tbAux.id_mail = 6
AND
    tbUser.status = 'A'
AND
    tbUser.email LIKE '%@%.%'
AND
    tbUser.id > 0
ORDER BY
    tbUser.name ASC
LIMIT
    0 , 200[/code]

I think its logical error, thank for any help.

D.Soul
Link to comment
Share on other sites

Try something like this (untested, in a rush):

[code]
SELECT
    DISTINCT
    tbUser.id ,
    tbUser.name ,
    tbUser.email
FROM
    tbUser
LEFT JOIN
    tbAux
ON
    tbAux.id_user = tbUser.id
WHERE
    tbAux.id_mail = 6
AND
    tbUser.status = 'A'
AND
    tbUser.email LIKE '%@%.%'
AND
    tbUser.id > 0
AND
    tbAux.id_user IS NULL
ORDER BY
    tbUser.name ASC
LIMIT
    0 , 200
[/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.