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
https://forums.phpfreaks.com/topic/27564-select-using-on-join/
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
https://forums.phpfreaks.com/topic/27564-select-using-on-join/#findComment-126390
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.