PDA

View Full Version : UNION sql query



Alx
13 Nov 2008, 02:17 PM
ok im getting an error using UNION. it works fine if the 'video' table is left out but as soon as i add the 'video' table it returns no results....
one of the problems is i ONLY need two columns for the video table (id, media_type) whereas I need 3 from all the others....
this is the first time i have used union so please help



-----
$q = "SELECT id,thumb_dir,media_type FROM images WHERE content_type in($content_type_string) UNION SELECT id,thumb,media_type from blog WHERE content_type in($content_type_string) UNION SELECT id, media_type from video WHERE content_type in($content_type_string) LIMIT $thumbs_index , 30";
-----


here are the column types
images
id:int(11) - Primary Key
thumb_dir:varchar(100)
media_type:varchar(5)
blog
id:int(11) - Primary Key
thumb_dir:varchar(100)
media_type:varchar(5)
video
id:varchar(30)
media_type:varchar(5)