从哪个表中检索数据

时间:2014-06-26 11:18:29

标签: mysql sql

SELECT username,
       password,
FROM table1
WHERE username = :username
UNION ALL
SELECT username,
       password,
FROM table2
WHERE username = :username

我想从table1或table2中找到从哪个表中检索的数据 而且,这些表中插入的数据是唯一的

提前致谢

1 个答案:

答案 0 :(得分:4)

添加包含以下信息的列:

SELECT 'table1' as which, username, password
FROM table1
WHERE username = :username
UNION ALL
SELECT 'table2' as which, username, password
FROM table2
WHERE username = :username;