Solved

MySQL - Join question

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Creating and Managing Databases with phpMyAdmin in cPanel.
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 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