Another stupid question (relational select)

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Another stupid question (relational select)

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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'
Post Reply