Can you just do SELECT t1.*, "t1" as tablename FROM t1 UNION SELECT t2.*, "t2" as tablename FROM t2
Roger -----Original Message----- From: Miguel Vaz [mailto:[EMAIL PROTECTED] Sent: 17 February 2008 00:04 To: mysql@lists.mysql.com Subject: select with table name Hi, I have a small issue that i can get my head around to solve: Is it possible to do a select from two tables using a union all (select * from t1 union all select * from t2), and have it display the table name in front of each row? What i need is, on the big resulting list, to know from which table the row came from. Example: Table: t1 ----------------------- id name ----------------------- 1 john 2 mary Table: t2 ----------------------- id name ----------------------- 1 paul 2 peter I need these results: ---------------------------------------- id name fromtable ---------------------------------------- 1 john t1 2 mary t1 3 paul t2 4 peter t2 Is this possible? If so, how? Thanks! Pag -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]