MYSQL 与哪里和喜欢而不是
MYSQL with Where and Like And not in
我比较两个表并输出行中没有的值。
SELECT one, two FROM `table1` WHERE `two` NOT IN
(SELECT `two2` FROM `table2`) AND `one` NOT IN (SELECT `one1` FROM `table2`)
我如何添加一个喜欢...喜欢行“%two”不在“%two2”中?
我喜欢检查:
SELECT one, two FROM table1 WHERE LIKE %two NOT IN (SELECT LIKE %two2 FROM table2)
因为在这个表中有时第一位是 0 但我必须淡出
我没有变量只有行名。我有什么办法可以做到吗?
您可以颠倒您的条件并改用棘手的 LEFT JOIN
。然后,您的查询将如下所示:
SELECT one, two FROM `table1`
LEFT JOIN `table2` ON
`table1`.`one` = `table2`.`one1`
OR `table1`.`two` = `table2`.`two2`
-- List others field comparasion using OR here --
WHERE `table2`.`one1` IS NULL;
这种方法将帮助您减少子查询的数量并大大提高性能和可读性。
我比较两个表并输出行中没有的值。
SELECT one, two FROM `table1` WHERE `two` NOT IN
(SELECT `two2` FROM `table2`) AND `one` NOT IN (SELECT `one1` FROM `table2`)
我如何添加一个喜欢...喜欢行“%two”不在“%two2”中?
我喜欢检查:
SELECT one, two FROM table1 WHERE LIKE %two NOT IN (SELECT LIKE %two2 FROM table2)
因为在这个表中有时第一位是 0 但我必须淡出
我没有变量只有行名。我有什么办法可以做到吗?
您可以颠倒您的条件并改用棘手的 LEFT JOIN
。然后,您的查询将如下所示:
SELECT one, two FROM `table1`
LEFT JOIN `table2` ON
`table1`.`one` = `table2`.`one1`
OR `table1`.`two` = `table2`.`two2`
-- List others field comparasion using OR here --
WHERE `table2`.`one1` IS NULL;
这种方法将帮助您减少子查询的数量并大大提高性能和可读性。