![]() |
Combine 3 MySQL queries into one?
I've got three tables, all with different numbers of columns. They all have a column 'cidname' to relate the groups between tables, and 'name' to relate individuals between tables. I'm currently using three "SELECT * FROM tablename WHERE cidname = 'blah'" to get my data, and having to pick out elements from the different result sets. I've been looking at JOIN and UNION stuff, but can't find an example I understand.
Code:
table1 Code:
cidname = abcd, name = Goober, data2 = blah123, dataa = blahz, datab = blahy, datac = blahx, data = foo |
select a.*, b.*, c.* from table1 a join table2 b on a.cidname = b.cidname join table3 c on a.cidname = c.cidname;
This (I think the syntax is correct) will work. To separate out the results, do something like: select a.name first_name, a.data2 somedata .............. This will rename the columns returned for the purpose of displaying / using the data. |
All times are GMT. The time now is 09:17 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|