If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Query issue

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-12-06, 06:33
pirox pirox is offline
Registered User
 
Join Date: Jun 2006
Posts: 1
Query issue

Hello all,

I'm new here and I have a question. There is a query im running which fails to execute on our servers. We run MYSQL 5 locally, while our server runs 4.0.25. What puzzels me is why the code is not running. The code is as follows:

select DISTINCT id from [] where []=1 and NOT EXISTS (select [] from [] where []=[]);

but the server tells us the following :

#1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'EXISTS (select [] from [] where []=[]) LIMIT

Can someone tell me whether mysql 4 supports NOT EXISTS? We even tried NOT IN, but no success...

Thank You.

Pirox
Reply With Quote
  #2 (permalink)  
Old 06-12-06, 07:10
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
subqueries are not supported until version 4.1
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 06-12-06, 11:17
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
I think what you need is more like:
Code:
select id
   from []
   LEFT JOIN []
      ON ([] = [])
   where 1 = []
      AND [] IS NULL
   GROUP BY [];
This should work much better in MySQL.

-PatP

Last edited by Pat Phelan; 06-12-06 at 11:52.
Reply With Quote
  #4 (permalink)  
Old 06-12-06, 11:26
Brett Kaiser Brett Kaiser is offline
Window Washer
 
Join Date: Nov 2002
Location: Jersey
Posts: 10,303
what the hell i sthat?
__________________
Brett
8-)

It's a Great Day for America everybody!

dbforums Yak CorralRadio 'Rita
dbForums Member List
I'm Good Once as I ever was

The physical order of data in a database has no meaning.
Reply With Quote
  #5 (permalink)  
Old 06-12-06, 11:41
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Doesn't []=[] always evaluate to true? I'm gonna plump for:
Code:
SELECT DISTINCT id 
FROM [] 
WHERE []=1
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #6 (permalink)  
Old 06-12-06, 11:54
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
Quote:
Originally Posted by pootle flump
Doesn't []=[] always evaluate to true? I'm gonna plump for:
Code:
SELECT DISTINCT id 
FROM [] 
WHERE []=1
Good catch on the [] = 1 part! I missed that, so I've amended my original suggestion.

I don't think it is safe to assume that [] will always equal [], so I think it is better left stated explicitly. If it isn't needed, I'm sure that it will get optimized out.

-PatP
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On