MySQL SubQuery - MySQL 3.23(MySQL 子查询 - MySQL 3.23)
问题描述
我有 2 个表,emp_master 和 passport_details.
emp_master(emp_id,first_name,email_id,dob,doj,status.........)护照详细信息(id,emp_id,passport_number,given_name,......).我正在尝试从没有输入 passport_details 的 emp_master 中获取 emp_id 和 first_name.
我尝试了不同的子查询组合,使用 NOT IN,NOT EXISTS.
SELECT emp_id,first_nameFROM emp_masterWHERE emp_id NOT IN(SELECT emp_id FROM passport_details WHERE status=1);我遇到错误
第 3 行的SELECT emp_id FROM passport_details WHERE status=1)"附近的 SQL 语法有错误我使用的是 MySQL 3.23.
我的问题是
<块引用>- MySQL 3.23 是否支持子查询?
- 从没有输入 passport_details 的 emp_master 中获取 emp_id 和 first_name 的最佳查询可能是什么.
select em.emp_id, em.first_name从emp_master em 离开加入passport_details pd在 pd.emp_id = em.emp_id 和 pd.status = 1其中 pd.emp_id 为空我没有要测试的 3.23 实例,但这应该可以.
I've 2 tables, emp_master and passport_details.
emp_master(emp_id,first_name,email_id,dob,doj,status.........)
passport_details(id, emp_id,passport_number,given_name,......).
I am trying to fetch emp_id and first_name from emp_master who have not entered passport_details.
I tried different combination of SubQueries, used NOT IN, NOT EXISTS.
SELECT emp_id,first_name
FROM emp_master
WHERE emp_id NOT IN(SELECT emp_id FROM passport_details WHERE status=1);
I am getting error
You have an error in your SQL syntax near 'SELECT emp_id FROM passport_details WHERE status=1)' at line 3
I am using MySQL 3.23.
My question is
- Do MySQL 3.23 supports SubQueries?
- What could be the optimal query to fetch emp_id and first_name from emp_master who have not entered passport_details.
select em.emp_id, em.first_name
from emp_master em left join passport_details pd
on pd.emp_id = em.emp_id and pd.status = 1
where pd.emp_id is null
I don't have a 3.23 instance to test with, but this should work.
这篇关于MySQL 子查询 - MySQL 3.23的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL 子查询 - MySQL 3.23
基础教程推荐
- 是否可以执行按位分组功能? 2021-01-01
- 无法解决整理冲突 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
