Joing data from three tables

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Joing data from three tables

Post by JayBird »

i have three tables

ocda_images_gd
ocda_images_ra
ocda_images_wd


the three tables have EXACTLY the same structure

Code: Select all

Field      Type          Null    Key     Default  Extra           Privileges                     
---------  ------------  ------  ------  -------  --------------  -------------------------------
id         int(3)                PRI     (NULL)   auto_increment  select,insert,update,references
path       varchar(255)  YES             (NULL)                   select,insert,update,references
caption    varchar(255)  YES             (NULL)                   select,insert,update,references
weighting  char(3)       YES             (NULL)                   select,insert,update,references
main_pic   char(1)       YES             (NULL)                   select,insert,update,references
active     char(1)       YES             (NULL)                   select,insert,update,references
I want to select the data from all 3 tables and display the information. The data from the tables is not related in anyway.

What query do i need to use?

Thanks

Mark
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Im guessing the UNION function would be useful, but is only available from verison 4 and my host is running bersion 3.23.55

Mark
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

If MySQL version >= 4.0.0
http://dev.mysql.com/doc/mysql/en/UNION.html

i think this is the easiest way. The other way I can think of is very sloppy (but it works) but would take some writing. Try UNION first, as I think this would suit you the best.
Post Reply