SQL:选择某列中有值的行,而该值不包含在另一个表中
有两张桌子 学生:SQL:选择某列中有值的行,而该值不包含在另一个表中,sql,Sql,有两张桌子 学生: ID | Name | Age ---+------+----- 1 | Alex | 19 2 | Matt | 23 3 | Ali | 19 ACTIONID | Description ---------+--------------------------- 1 | Alex hasn't paid yet 行动: ID | Name | Age ---+------+----- 1 | Alex | 19 2 | Matt | 23
ID | Name | Age
---+------+-----
1 | Alex | 19
2 | Matt | 23
3 | Ali | 19
ACTIONID | Description
---------+---------------------------
1 | Alex hasn't paid yet
行动:
ID | Name | Age
---+------+-----
1 | Alex | 19
2 | Matt | 23
3 | Ali | 19
ACTIONID | Description
---------+---------------------------
1 | Alex hasn't paid yet
我想选择19岁的学生ID。但不希望从操作
表中选择名称包含在任何描述列行中的学生
所以结果应该是
ID: 3
怎么做?有人能帮我吗?试试这个:
SELECT student.ID
FROM Students student
WHERE 0 = (SELECT COUNT(*)
FROM Actions action
WHERE action.Description LIKE CONCAT('%', student.Name, '%')
AND student.Age = 19;
如果我理解你的问题
select ID from Students where Age = 19
你不明白我的问题,谢谢。这是正确的。您也可以使用EXISTS方法而不是“0=(选择(*)…”方法。查看Internet上的工作原理:)