Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

have mysql select statement return fully qualified column names like table.field

Tags:

sql

mysql

is there a way to have a mysql select statement return fully qualified column names like "table.field" without using AS for every single field?

like so:

SELECT * 
FROM  table1  
LEFT JOIN table2 on table1.f_ID = table2.ID  

and the result would be: "table1.ID", "table1.name", "table2.ID", "table2.name", ...

like image 204
handsomeGun Avatar asked Mar 01 '23 05:03

handsomeGun


2 Answers

If you are using PHP you can use PDO to get this result.

$PDO->setAttribute(PDO::ATTR_FETCH_TABLE_NAMES, true);

See SQL Select * from multiple tables for more information.

like image 136
Paul Hutchinson Avatar answered Mar 05 '23 16:03

Paul Hutchinson


Not really. You could write some dynamic SQL to accomplish this, but it wouldn't be simple. If you really want the dynamic SQL, let me know and I could try to whip something up.

like image 20
user12861 Avatar answered Mar 05 '23 14:03

user12861