Solved

SELECT comparing to entire column

Posted on 2004-10-15
2
240 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

10 Experts available now in Live!

Get 1:1 Help Now