关于sql中=all的问题
DELETEFROMjob_historyjWHERE(employee_id,job_id)=ALL(SELECTemployee_id,job_idFROMemplo...
DELETE FROM job_history j WHERE (employee_id, job_id) = ALL (SELECT employee_id, job_id
FROM employees e WHERE j.employee_id = e.employee_id and j.job_id = e.job_id )
DELETE FROM job_history j WHERE (employee_id, job_id) = (SELECT employee_id, job_id FROMemployees e WHERE j.employee_id = e.employee_id and j.job_id = e.job_id )
请问下·这两句sql 有什么区别,为什么第1条sql比第二条sql删除的记录要多呢?
当 ALL (SELECT employee_id, job_id
FROM employees e WHERE j.employee_id = e.employee_id and j.job_id = e.job_id )
这个查询结果 是 no row seleced
外层的sql 把 job_history 表的所有记录都delete了·为什么啊 展开
FROM employees e WHERE j.employee_id = e.employee_id and j.job_id = e.job_id )
DELETE FROM job_history j WHERE (employee_id, job_id) = (SELECT employee_id, job_id FROMemployees e WHERE j.employee_id = e.employee_id and j.job_id = e.job_id )
请问下·这两句sql 有什么区别,为什么第1条sql比第二条sql删除的记录要多呢?
当 ALL (SELECT employee_id, job_id
FROM employees e WHERE j.employee_id = e.employee_id and j.job_id = e.job_id )
这个查询结果 是 no row seleced
外层的sql 把 job_history 表的所有记录都delete了·为什么啊 展开
展开全部
比较符"="和"=ALL”的区别:
1、"="是单行比较符,,"=ALL"是多行比较符。
2、"="是一对一比较相等,,"=ALL"是一对多比较全部相等。
问题的两条语句的结果一样的。原因是子查询中的
WHERE j.employee_id = e.employee_id and j.job_id = e.job_id
限定的条件是一样的,当然返回结果也是一样的,而且都是返回单行。如果返回多行第二条语句会出错的。你说的第一条比第二条删除的多是错觉。
ALL (SELECT employee_id, job_id
FROM employees e WHERE j.employee_id = e.employee_id and j.job_id = e.job_id )
这个语句不完整啊。你去掉了delete后面表,j 代表谁?
1、"="是单行比较符,,"=ALL"是多行比较符。
2、"="是一对一比较相等,,"=ALL"是一对多比较全部相等。
问题的两条语句的结果一样的。原因是子查询中的
WHERE j.employee_id = e.employee_id and j.job_id = e.job_id
限定的条件是一样的,当然返回结果也是一样的,而且都是返回单行。如果返回多行第二条语句会出错的。你说的第一条比第二条删除的多是错觉。
ALL (SELECT employee_id, job_id
FROM employees e WHERE j.employee_id = e.employee_id and j.job_id = e.job_id )
这个语句不完整啊。你去掉了delete后面表,j 代表谁?
更多追问追答
追问
DELETE FROM job_history j WHERE (employee_id, job_id) = ALL (SELECT employee_id, job_id
FROM employees e WHERE j.employee_id = e.employee_id and j.job_id = e.job_id )
上面的sql现象是
当内层子查询
SELECT employee_id, job_id
FROM employees e WHERE j.employee_id = e.employee_id and j.job_id = e.job_id 返回0行记录时,外层把 job_history 所有记录删掉。 就是这里没搞懂
追答
抛开主句Delete... ...Where只运行下列句子是不可能的。
SELECT employee_id, job_id
FROM employees e WHERE j.employee_id = e.employee_id and j.job_id = e.job_id
在这个语句where j.employee_id中 j 已经不是job_history 的别名了,你是怎么运行的?怎么知道返回0行记录?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询