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 > sql problem. Help please

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-18-04, 00:26
Paingiver Paingiver is offline
Registered User
 
Join Date: Feb 2004
Posts: 14
sql problem. Help please

SQL problem in mysql
INSERT INTO task (user_id, poster_id, project_id, mount_id, subject, time, finish, priority_id, type_id, status_id) VALUES (999, 999, 111, (select MAX(ID) from task where subject = 'Software', 'training', -1, -1, 2, 2, 1);

and

UPDATE task SET mount_id = 2
Where Id = select Max(ID) from task where subject ='Consulting';

they both gave me this error :

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(ID) from task where subject ='Consulting'' at line 1

Please and Thank You
Reply With Quote
  #2 (permalink)  
Old 02-18-04, 08:00
ika ika is offline
Registered User
 
Join Date: Oct 2003
Location: Slovakia
Posts: 482
Re: sql problem. Help please

Quote:
Originally posted by Paingiver
SQL problem in mysql
INSERT INTO task (user_id, poster_id, project_id, mount_id, subject, time, finish, priority_id, type_id, status_id) VALUES (999, 999, 111, (select MAX(ID) from task where subject = 'Software', 'training', -1, -1, 2, 2, 1);

and

UPDATE task SET mount_id = 2
Where Id = select Max(ID) from task where subject ='Consulting';

they both gave me this error :

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(ID) from task where subject ='Consulting'' at line 1

Please and Thank You
What version of MySQL you are using? Because subselects (nested queries) are supported only 4.1.x and newer version
Reply With Quote
  #3 (permalink)  
Old 02-18-04, 08:59
ursus ursus is offline
Registered User
 
Join Date: Feb 2004
Location: Erehwon
Posts: 18
Don't know about the second query, but you didn't close the parens around the subquery in your first one

[code]
INSERT INTO task (user_id, poster_id, project_id, mount_id, subject, time, finish, priority_id, type_id, status_id) VALUES (999, 999, 111, (select MAX(ID) from task where subject = 'Software'), 'training', -1, -1, 2, 2, 1);
[\code]
Reply With Quote
  #4 (permalink)  
Old 02-18-04, 09:25
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
PHP Code:
insert 
  into task 
     
user_id
     
poster_id
     
project_id
     
mount_id
     
subject
     
time
     
finish
     
priority_id
     
type_id
     
status_id
     

select 999
     
999
     
111
     
max(id
     , 
'training'
     
, -1
     
, -1
     
2
     
2
     
1
  from task
 where subject 
'Software' 
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 02-18-04, 18:28
Paingiver Paingiver is offline
Registered User
 
Join Date: Feb 2004
Posts: 14
MySql v 4.0.17, so i guess i should update my mysql. I'm downloading it now.
Reply With Quote
  #6 (permalink)  
Old 02-18-04, 18:48
Paingiver Paingiver is offline
Registered User
 
Join Date: Feb 2004
Posts: 14
To Ursus,

Yes i did close the statement.

Thank You
Reply With Quote
  #7 (permalink)  
Old 02-18-04, 20:46
Paingiver Paingiver is offline
Registered User
 
Join Date: Feb 2004
Posts: 14
After updating mysql to v 5.0.0a i now have this error:

You can't specify target table 'task' for update in FROM clause
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