Bluehost.com Web Hosting $6.95

mysql, dreaded error 1064

This is a discussion on mysql, dreaded error 1064 within the MySQL Database forums, part of the Database Forums category; Hi, I've new to mysql and sql in general and I'm trying to find the correct syntax to ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-26-2007
che10234@hotmail.com
 
Posts: n/a
Default mysql, dreaded error 1064

Hi,

I've new to mysql and sql in general and I'm trying to find the
correct syntax to delete all rows EXCEPT the one row with the max
value of a certain field.

For example, my DB has:
UserName Sessions
Chris 2
Chris 4
Mark 4
Chris 3
Mark 2

I want to delete everything except:
Chris 4
Mark 4

So for each UserName, delete everthing except the row with the most
sessions.

Here's what I thought would work:


DELETE * from dbname as A where A.Sessions <> (select MAX(Sessions)
from dbname where UserName = A.UserName);

When I try this with mySql 4.1 I get:

Error Code : 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 'select MAX(Sessions) from dbname where U
(0 ms taken)


Any ideas?!
Thanks

Reply With Quote
  #2 (permalink)  
Old 03-27-2007
Paul Lautman
 
Posts: n/a
Default Re: mysql, dreaded error 1064

che10234@hotmail.com wrote:
> Hi,
>
> I've new to mysql and sql in general and I'm trying to find the
> correct syntax to delete all rows EXCEPT the one row with the max
> value of a certain field.
>
> For example, my DB has:
> UserName Sessions
> Chris 2
> Chris 4
> Mark 4
> Chris 3
> Mark 2
>
> I want to delete everything except:
> Chris 4
> Mark 4
>
> So for each UserName, delete everthing except the row with the most
> sessions.
>
> Here's what I thought would work:
>
>
> DELETE * from dbname as A where A.Sessions <> (select MAX(Sessions)
> from dbname where UserName = A.UserName);
>
> When I try this with mySql 4.1 I get:
>
> Error Code : 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 'select MAX(Sessions) from dbname where U
> (0 ms taken)
>
>
> Any ideas?!
> Thanks


Use Google to search this group for the words "strawberry query" (include
the quotes).


Reply With Quote
  #3 (permalink)  
Old 03-27-2007
che10234@hotmail.com
 
Posts: n/a
Default Re: mysql, dreaded error 1064

What an interesting response....I feel like I've been told some secret
code. I found it and I'll try it out, thanks. Although I still don't
see what is syntactically wrong with my first attempt.


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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:53 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0