编辑:我需要展示的是那些来自SQL查询列表中的电子邮件不要出现在tresp中。
我有以下代码:
SELECT * FROM tresp WHERE email IN ('[email addy here]','[email addy here]','
[email addy here]','[email addy here]','[email addy here]')
这可能听起来很奇怪,但我想要做的其实就是在tresp中显示 NOT 的电子邮件地址 - 可能吗?
干杯,
小时。
答案 0 :(得分:5)
那么......你想要NOT IN
吗?
SELECT *
FROM tresp
WHERE email NOT IN ('[email addy here]','[email addy here]')
或者您想要电子邮件地址吗?
SELECT DISTINCT email
FROM tresp
WHERE email NOT IN ('[email addy here]','[email addy here]')
答案 1 :(得分:3)
棘手的问题,这个解决方案不是很优雅,但它有效;
SELECT * FROM (
SELECT 'email1' AS email UNION
SELECT 'email2' UNION
SELECT 'email3' UNION
SELECT 'email4' UNION
SELECT 'email5'
) AS a WHERE a.email NOT IN (SELECT email FROM tresp);
If you run into the same charset problems I had, create the table with default charset utf-8.
编辑:添加了一个AS,因为没有它,旧的MySQL似乎有麻烦。
SQLFiddle的演示。
答案 2 :(得分:0)
它不漂亮,但这可能会做你想要的,试图找到一个更优雅的解决方案,但这至少有效
SELECT
findTheseEmails.email
FROM
(
SELECT CONVERT(_latin1 'test@foo.com' USING utf8) AS email
UNION SELECT CONVERT(_latin1 'bar@fooo.com' USING utf8)
UNION SELECT CONVERT(_latin1 'woww@foo.com' USING utf8)
UNION SELECT CONVERT(_latin1 'teasfsafst@foo.com' USING utf8)
) AS findTheseEmails
LEFT JOIN tresp
ON tresp.email = findTheseEmails.email
WHERE tresp.email IS NULL