|  | Posted by David Haynes on 01/09/06 03:08 
kiqyou_vf wrote:> I have a page that displays multiple search results. On each search
 > result I want unique information from two or more tables to be
 > displayed. All tables have a "client_id" column. I need the main query
 > to display results based on the $_GET['keywords'] and a second table to
 > display results based on the "client_id" of the main query. I don't
 > have any code as of yet to show you. I have done some research on UNION
 > and found this on mysql.com:
 >
 > "Selected columns listed in corresponding positions of each SELECT
 > statement should have the same type. (For example, the first column
 > selected by the first statement should have the same type as the first
 > column selected by the other statements.) The column names used in the
 > first SELECT statement are used as the column names for the results
 > returned."
 >
 > Is this going to be a problem since the names and information are going
 > to be  different on each of my tables.
 >
 It sounds more like you want an inner join not a union (unless the
 tables are from different data sources). It's hard to advise without
 some concrete details, but it *sounds* like you have a table 'a' with a
 client_id and some other values and a table 'b' with a client_id and
 some other values and you want to show values from a and b.
 
 So, the select would be something like:
 select
 a.column1,
 a.column4,
 b.column7
 from
 a,
 b
 where
 a.client_id = b.client_id	<-- inner join
 and	(any other conditions)
 
 -david-
 [Back to original message] |