Solved

MySQL - Join question

Posted on 2013-06-21
3
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

707 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