mysql table name
Moderator: General Moderators
mysql table name
i'm planning on joining a bunch of tables and using a loop to display the html for every row, but in every row it has to say which table it came from. how do i get the name of the table?
re
i wasnt planniing on using union just plain old join (select col1, col2 from table1, table2...) since i'm selecting the same colums from each table i don't see how union would help. and even if i did use union how would i get the table name?
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
you write it into the query as a "fake" column returned by supplying a string literal. If the tables have the same structure, joining them will only return massive duplicate records or no records, depending on how you write the query. It sounds like a UNION would be best, unless you can provide more information.
re
i have 5-6 tables that each have a number of colums that are the same and a few that are distinct to that table. on the page i'm talking about i want to output all the colums that are the same in each table.because of the way it's set up there shouldn't be any duplicates. are you suggesting adding a colum to each table with the table name? is that the only way?
i'm sorry but i'm kinda new to php/mysql and i have no idea what that means.
Code: Select all
select
'table1', *
from table1
union
select
'table2', *
from table2
........
- kbrown3074
- Forum Contributor
- Posts: 119
- Joined: Thu Jul 20, 2006 1:36 pm
If you are using tables with fields of the same names you will have problems using '*'. You will need to explicitly state 'table.field' in the select statement. You will have to do the same in the WHERE clause of the statement as well.
Code: Select all
SELECT tbl1.field1,tbl2.field2 FROM tbl1,tbl2 WHERE tbl1.field1 = tbl2.field2