Solved

MySQL - Join question

Posted on 2013-06-21
3
350 Views
Last Modified: 2013-06-21
I have a real estate idx database with 3 tables res, seo, fagents.
fagents is a table containing info on agents from my company and no other company. I'm trying to populate a property detail page and if the property is listed by my company, I want to show additional details about the agent (from the fagents table)

Here is my query:

SELECT * FROM res,seo,fagents WHERE res.listID = "#URL.listID#" AND res.listID = seo.listID AND res.agentID = fagents.agentID

The problem with this query is that if the property is listed by another company then  res.agentID = fagents.agentID wont find a match and the property will not be shown.

How can I make this work? Any help appreciated!
0
Comment
Question by:Bang-O-Matic
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 39266581
Switch to an OUTER JOIN on the "fagents" table, so the query always returns the "res " record, even when there's no matching agent.

SELECT res.listID, ....other columns ...
FROM  res
          INNER JOIN seo ON res.listID = seo.listID
          LEFT JOIN fagents ON res.agentID = fagents.agentID
WHERE res.listID = <cfqueryparam value="#URL.listID#" cfsqltype="cf_sql_varchar">
0
 

Author Closing Comment

by:Bang-O-Matic
ID: 39266602
when i finish this site, Im going to add "programming by _agx_" in the footer :)
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39266784
Haha, glad to help where I can :)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Creating and Managing Databases with phpMyAdmin in cPanel.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question