Page 1 of 1
MySql question
Posted: Mon Mar 03, 2003 12:50 am
by smoky989
OK, here's my situation...I have three tables. Each of them have a field called name, position, and email. l want to write a query thta will list the names from the 3 tables, the positions from the three tables, and the email from the three tables. I want to do this with 3 columns. It seems like something thta can be done but I'm drawing a blank. So...
column 1 - names from the three tables
column 2 - positions from the 3 tables
column 3 - email from the three tables
any ideas? Thanks in advance.
Posted: Mon Mar 03, 2003 2:15 am
by twigletmac
Am I right in thinking that you want something along the lines of:
Code: Select all
name1 | position1 | email1
name2 | position2 | email2
name3 | position3 | email3
name4 | position4 | email4
name5 | position5 | email5
etc...
Mac
Yes
Posted: Mon Mar 03, 2003 10:56 am
by smoky989
Yeah thats exactly what I want. Three columns with the info from the three tables.
Posted: Tue Mar 04, 2003 3:08 am
by twigletmac
What code have you got so far?
Mac
Posted: Tue Mar 04, 2003 5:24 am
by kcomer
Use temp tables to hold the data. This page from the MyQL manual explains how to select data from one or more tables and hold the results in a new temp table. This should do what your looking for.
http://www.mysql.com/doc/en/INSERT_SELECT.html
Keith
Posted: Tue Mar 04, 2003 8:04 am
by Rob the R
You could also use the
UNION operator if you're using at least MySQL 4.0:
Code: Select all
select name, position, email
from table1
UNION
select name, position, email
from table2
UNION
select name, position, email
from table3