Page 1 of 1

Another stupid question (relational select)

Posted: Thu Jul 27, 2006 5:14 pm
by Luke
OK, I just bought an O'Reilly book on mysql and it's on it's way, so soon I will stop asking these stupid questions (hopefully) but for now...

I have table one with business info, table two with points info, and table three (that relates them) with business_id & points_id. How do i select all the business information, but with the lat and lon values from points...

my tables:

businesses:

id
name
owner
address
phone

points:

id
lat
lon

businesses_points:

business_id
point_id

Posted: Thu Jul 27, 2006 5:23 pm
by feyd
something like

Code: Select all

SELECT
  `businesses`.*
FROM
  `points`
LEFT JOIN
  `businesses_points`
  ON
    `points`.`id` = `businesses_points`.`point_id`
LEFT JOIN
  `businesses`
  ON
    `businesses_points`.`business_id` = `businesses`.`id`
WHERE
  `points`.`lat` = '123'
  AND
  `points`.`lon` = '321'