我通过在mysql中连接两个以上的表来创建表。 现在我想使用该查询作为另一个查询中的表名的子查询传递。 我可以用它吗?
我有三个表,内部用以下查询加入它们。
SELECT A.emp_id, B.designation_name, C.dept_name, A.fname, A.lname, A.address, A.city, A.contactnumber1, A.contactnumber2,
A.email, A.salary, A.dob, A.doj, A.created_on, A.modified_on
FROM employee_master A
INNER JOIN designation_master B
INNER JOIN depart_master C
ON A.designation_id = B.id AND A.department_id = C.id
现在我想将此查询用作子查询以获取表中的行数。
答案 0 :(得分:0)
我不确定我明白你的意思,但你可以从选择中选择:
SELECT ...
FROM (
SELECT A.emp_id, B.designation_name, C.dept_name, A.fname, A.lname, A.address, A.city
, A.contactnumber1, A.contactnumber2, A.email, A.salary, A.dob, A.doj
, A.created_on, A.modified_on
FROM employee_master A
JOIN designation_master B
ON A.designation_id = B.id
JOIN depart_master C
ON A.department_id = C.id
) AS T
WHERE ...
您可以通过创建视图来“命名”查询:
CREATE VIEW WHATEVER AS
SELECT A.emp_id, B.designation_name, C.dept_name, A.fname, A.lname, A.address, A.city
, A.contactnumber1, A.contactnumber2, A.email, A.salary, A.dob, A.doj
, A.created_on, A.modified_on
FROM employee_master A
JOIN designation_master B
ON A.designation_id = B.id
JOIN depart_master C
ON A.department_id = C.id
然后可以参考:
SELECT ...
FROM WHATEVER
WHERE ...