473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

NOT EXISTS syntax problem

New at this :-)
2 tables
demographic visits
---------------- ------------------
custID | name | |custID | other stuff |
---------------- ----------------------

I want all those names where the custID doesnt appear in vists

select name FROM demographic WHERE NOT EXISTS (SELECT custID FROM
visits WHERE demographic.custID=visits.custID);

is a syntax error

Jul 17 '05 #1
5 1930
pauld wrote:
I want all those names where the custID doesnt appear in vists

select name FROM demographic WHERE NOT EXISTS (SELECT custID FROM
visits WHERE demographic.custID=visits.custID);

is a syntax error


Which version of MySQL are you using? This syntax is supported by MySQL
version 4.1 and up.
JW

Jul 17 '05 #2
On 29 May 2005 00:26:09 -0700, "pauld" <pd****@yahoo.co.uk> wrote:
New at this :-)

2 tables
demographic visits
---------------- ------------------
custID | name | |custID | other stuff |
---------------- ----------------------

I want all those names where the custID doesnt appear in vists

select name FROM demographic WHERE NOT EXISTS (SELECT custID FROM
visits WHERE demographic.custID=visits.custID);

is a syntax error


Not in most databases. Which one are you using? What's the actual error
message?

There are various ways of rewriting the query to produce the same result
(there's nothing wrong with your syntax on most databases though) - but it
depends which one you're using.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #3
Im not at work at the moment .....

gentoo linux server with probably 4.0.22

I suppose its possibe to rewrite it with a JOIN ( or perhaps a NOT JOIN ?)?

clues please.

Jul 17 '05 #4
p cooper (pd********************@yahoo.co.uk) wrote:
: Im not at work at the moment .....

: gentoo linux server with probably 4.0.22

: I suppose its possibe to rewrite it with a JOIN ( or perhaps a NOT JOIN ?)?

: clues please.

left join the tables on the shared column, and look for rows where the
second table has null in the joined column. Those are the rows where the
right table doesn't exist.

--

This space not for rent.
Jul 17 '05 #5
pauld wrote:
New at this :-)
2 tables
demographic visits
---------------- ------------------
custID | name | |custID | other stuff |
---------------- ----------------------

I want all those names where the custID doesnt appear in vists

select name FROM demographic WHERE NOT EXISTS (SELECT custID FROM
visits WHERE demographic.custID=visits.custID);

is a syntax error


Pauld,

Depending on your MySQL version, try something like:

SELECT name FROM demographic WHERE custID NOT IN (SELECT DISTINCT custID
FROM visits;

(the DISTINCT just means do unnecessarily return duplicate values).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: lawrence | last post by:
Google can't find me a good example of how to use the "if exists" syntax in MySql. Is it right that to use it this way: INSERT INTO IF EXISTS tMyTable VALUES("xxlk", "lkjlkjlkjljk") I want...
2
by: Bryan Rasmussen | last post by:
Hi I have a little program that is importing from os.path import exists, join, isdir, normpath, isfile at one point in my program I check if a file exists using if exists("c:\projects"): and...
2
by: Jonathan | last post by:
I am looking for a simple way to check if a database table exists. I keep getting advice to use "Try.. Catch" and other error handling methods, but I obviously don't want to have to display an...
0
by: Gamb? | last post by:
Hello! I've got some sort of syntax problem that doesn't seem to make a lot of sense. I'm developing a Categories Theory application and because of that I need to make big, and by "big" I mean...
1
by: Ninjaboy | last post by:
I'm trying to run NOT EXISTS or NOT IN query to find out wich records in one table do not match the other and mysql just gives me weird error. QUERY: SELECT cust_id FROM customers WHERE...
3
by: crazy_nelly | last post by:
To validate that a function exists on the page, one must simply use the syntax: if ( window.funcName ) //... However, the same syntax does not seem to work when attempting to validate that a...
5
by: ST | last post by:
Hi, I'm sort of in a rush here...I'm sort of new to vb.net and I'm trying to write the syntax to check a sql table to see if the record already exists based on firstname and lastname text fields...
1
by: bpforte | last post by:
Hello, I need help with building query, basically I need to select all records from one table that don't exists in second table with status 1, but they can exists in second table with status 0, to...
3
by: NHM | last post by:
I don't know if it's just me, but DB2 seems to have the worst syntatic parser ever created! Even after triple checking the documentation online, for the syntax of the statements the CLP seems to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.