Solved

MySQL - Join question

Posted on 2013-06-21
3
344 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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now