Solved

SELECT comparing to entire column

Posted on 2004-10-15
2
242 Views
Last Modified: 2006-11-17
Hi.

I have a query I am trying to do that I can not figure out. Any help will be appreciated.

I am trying to compare records in two tables (property and hotel_specific). Some records will have a link (p.id = h.trav_id) but for some the "h.trav_id" is missing. I want the results of the query to show all the records that are NOT a match. I have tried the below query but it even returns records that do have a match.

SELECT DISTINCT p.id, p.name, c.country_name
FROM property p, countries c, hotel_specific h
WHERE p.country = c.country_code
AND c.country_rid IN (6)
AND p.id != h.trav_id

Any body have the answer?

Thanks.

T
0
Comment
Question by:td234
2 Comments
 
LVL 33

Accepted Solution

by:
snoyes_jw earned 250 total points
ID: 12319992
Are you trying to get the properties that do not have a matching hotel?

SELECT p.id, p.name, c.country_name
FROM property p, countries c
LEFT JOIN hotel_specific h ON p.id = h.trav_id
WHERE p.country = c.country_code
AND c.country_rid IN (6)
AND h.trav_id IS NULL;
0
 
LVL 2

Author Comment

by:td234
ID: 12321237
That's it. Thanks.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 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