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 https://forums.phpfreaks.com/topic/278270-get-the-table-name-from-query-that-query-3-tables/ Share on other sites More sharing options...
DaveyK Posted May 22, 2013 Share Posted May 22, 2013 Set a static variable inside the query itself ( SELECT 'users' as 'table' FROM users ) UNION ALL ( SELECT 'messages' as 'table' FROM messages ) Link to comment https://forums.phpfreaks.com/topic/278270-get-the-table-name-from-query-that-query-3-tables/#findComment-1431539 Share on other sites More sharing options...
Lala55 Posted May 27, 2013 Share Posted May 27, 2013 Query: <pre>SELECT * FROM sys.tables</pre> or <pre>SELECT * FROM sysobjects WHERE xtype = 'U'</pre> --- If you are using Oracle, you can use one of these: <pre>SELECT * FROM all_tables;</pre> or <pre>SELECT * FROM all_objects WHERE object_type = 'TABLE';</pre> Link to comment https://forums.phpfreaks.com/topic/278270-get-the-table-name-from-query-that-query-3-tables/#findComment-1432487 Share on other sites More sharing options...
Lala55 Posted August 5, 2013 Share Posted August 5, 2013 On 5/27/2013 at 9:24 AM, Lala55 said: Query: <pre>SELECT * FROM sys.tables</pre> or <pre>SELECT * FROM sysobjects WHERE xtype = 'U'</pre> --- If you are using Oracle, you can use one of these: <pre>SELECT * FROM all_tables;</pre> or <pre>SELECT * FROM all_objects WHERE object_type = 'TABLE';</pre> Sometimes, the process of building and using queries is a simple matter of selecting fields from a table, perhaps applying some criteria, and then viewing the results. But what if, as is more often the case, the data you need is spread out in more than one table? Fortunately, you can build a query that combines information from multiple sources...... Duplichecker - free online plagiarism checker Link to comment https://forums.phpfreaks.com/topic/278270-get-the-table-name-from-query-that-query-3-tables/#findComment-1443503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.