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

I want to find from which table the data as been retrieved whether from table1 or table2 And ya the inserted data in these tables are unique

Thanks in advance

Sadikhasan
  • 17,858
  • 20
  • 77
  • 117
Hardik Amal
  • 1,213
  • 1
  • 16
  • 23

1 Answers1

4

Add a column with this information:

SELECT 'table1' as which, username, password
FROM table1
WHERE username = :username
UNION ALL
SELECT 'table2' as which, username, password
FROM table2
WHERE username = :username;
Gordon Linoff
  • 1,198,228
  • 53
  • 572
  • 709
  • can u tell me how can i store the obtained table name in string...$getrole = $row['which']; i m doing this but i m getting null value – Hardik Amal Jun 26 '14 at 11:40
  • @HardikAmal . . . Something like the code in your comment should work. That is a different question, and you can ask another question with the focus on the application code. – Gordon Linoff Jun 26 '14 at 12:11
  • some syntax error was there got solved...thanks a lot brother for the help – Hardik Amal Jun 26 '14 at 12:22