houssam_ballout Posted May 22, 2013 Share Posted May 22, 2013 Hello,I had this issue in mysql:I had made a query which select data from 3 tables, using UNION command, and its getting the results, when I want to display the results in a php page , I need to know the table that each record had been retrieved from, how can I do it?Thanks in advance Link to comment Share on other sites More sharing options...
justsomeguy Posted May 22, 2013 Share Posted May 22, 2013 Include the table name as a field. SELECT 'table1' AS `table`, * FROM table1 UNION SELECT 'table2' AS `table`, * FROM table2 UNION SELECT 'table3' AS `table`, * FROM table 3 Link to comment Share on other sites More sharing options...
jaseervp@ymail.com Posted May 30, 2013 Share Posted May 30, 2013 select column_name , 'table1' as Table from table1unionselect column_name , 'table2' as Table from table2unionselect column_name , 'table3' as Table from table3 You can identify the table name form Table Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now