转 mysql like子查询语句_mysql – 使用’LIKE’和SQL子查询的结果
首先,此查询不应该正常工作:
SELECT *
From Customers
WHERE Customers.ContactName = (SELECT FirstName
from Employees as E, orders as O
WHERE LIMIT 1);
因为WHERE LIMIT 1不是正确的SQL.而且,您应该学会使用正确的连接语法.据推测,你打算:
SELECT c.*
From Customers c
WHERE c.ContactName = (SELECT FirstName
FROM Employees as E JOIN
Orders as O
ON . . .
LIMIT 1
);
你可以想象在子查询中添加LIKE而不是=和’%’:
WHERE c.ContactName LIKE (SELECT CONCAT('%', FirstName, '%') . . .
但我会用EXISTS写这个:
SELECT c.*
From Customers c
WHERE EXISTS (SELECT 1...
浏览更多内容请先登录。
立即注册
更新于:2025-01-24 01:38:57
相关内容
推荐内容