It is currently Wed Feb 08, 2012 5:43 pm

All times are UTC + 2 hours [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: query multiple tables and i think my statement is wrong
PostPosted: Fri Oct 10, 2008 8:42 pm 
Offline

Joined: Fri Oct 10, 2008 8:40 pm
Posts: 1
Hey all,

Ive been trying to put together a php page for the last couple weeks that does a query on multiple tables at 1 time, and returns the results from each. In other words, i put in a search, it searches all the tables, then returns the results from whatever tables it finds my data in. each table is extremely different from the other, and as is the data. Im pretty sure that its just my statement that is wrong. Here is my statement but I cant seem to get it working right. Any help would be greatly appreciated.

select 'table1' results from table1 where field1= '$var' or field2 = '$var'
union
select 'table2' results from table2 where field1 = '$var'
union
select 'table3' results from table3 where field1 = '$var'

$var is my search that is put in.

This is making me lose my mind. Please help


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 14, 2008 11:52 pm 
Offline

Joined: Sun May 02, 2004 11:34 pm
Posts: 6500
Location: toronto, canada
select fieldname1, fieldname2 from table where fieldname = '$var'
union
select fieldname1, fieldname2 from table where fieldname = '$var'


Note that when you do this, you need to make sure that the fields in the union tables are of the same datatype as the first query

_________________
Lostboy

Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 2 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron