[thelist] [mysql] join

Jane De'Ath janed at oakwebdesign.com.au
Mon Jan 26 19:22:43 CST 2004


Would any PHP programmers who live in Adelaide South Australia please contact me off list if interested in contract work building CMS sites
Janed at oakwebdesign.com.au
Jane
  ----- Original Message ----- 
  From: Joshua Olson 
  To: thelist at lists.evolt.org 
  Sent: Saturday, January 24, 2004 3:54 AM
  Subject: Re: [thelist] [mysql] join 


  ----- Original Message ----- 
  From: "kris burford" <kris at midtempo.net>
  Sent: Friday, January 23, 2004 12:13 PM


  > $sql_one = "select id_one, id_two, some_other_stuff from table_one where
  x";
  > query
  > fetch_rows
  > $sql_two = "select name from table_two where id = id_one";
  > $sql_three = "select name from table_two where id = id_two";

  > is there any way that this can be done in a single request? could really
  do
  > without the extra overhead on the db...

  Kris,

  Yes, there is.  You'll want to look at the UNION syntax (or UNION ALL if you
  don't need duplicates removed):

  SELECT table_two.name, some_other_stuff
  FROM table_two
  INNER JOIN table_one
  ON table_one.id_one = table_two.id
  WHERE [x]
  UNION ALL
  SELECT table_two.name, some_other_stuff
  FROM table_two
  INNER JOIN table_one
  ON table_one.id_two = table_two.id
  WHERE [x]

  <><><><><><><><><><>
  Joshua Olson
  Web Application Engineer
  WAE Tech Inc.
  http://www.waetech.com/service_areas/
  706.210.0168


  -- 
  * * Please support the community that supports you.  * *
  http://evolt.org/help_support_evolt/

  For unsubscribe and other options, including the Tip Harvester 
  and archives of thelist go to: http://lists.evolt.org 
  Workers of the Web, evolt !


More information about the thelist mailing list