I have two tables,
first table structure (data) :
-id
-name
-title
-mail
-source_id
and second table ( mail ) :
-id
-record_id
-mail
-date
there may be some duplicate records in data table and some records with empty mail field.
im sending emails to these clients and i want to save whos email has been sent with time in mail table.
and i want to exclude records which their emails has been already sent
i use this query :
SELECT * FROM `data`
LEFT OUTER JOIN `mail`
ON `data`.`source_id` != `mail`.`record_id`
WHERE `data`.`mail` != ''
ORDER BY `data`.`id` ASC LIMIT 1
also i tried :
SELECT * FROM `data`
LEFT OUTER JOIN `mail`
USING(`mail`)
WHERE `data`.`mail` != ''
ORDER BY `data`.`id` ASC LIMIT 1
but it still shows duplicate records and dont exclude records from mail table
any ideas ? or better solution ? btw i cant alter first table and add a new field for checking sent emails
thanks in advance
try this
let’s change
!=toIS NOT NULL(I also think you should use<>instead of!=)UPDATE: let’s try DISTINCT