max(id) as

what is wrong here:
mySQL="SELECT ume,licenses, max(id) as maxd FROM demo WHERE ume='" &pklkp&"'"

i got syntax error on max(id) as maxd
?
sasha85Asked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
ok:
mySQL="SELECT ume,licenses, (select max(id) from demo) as maxd FROM demo WHERE ume='" &pklkp&"'"

Open in new window

0
 
Cornelia YoderArtistCommented:
Show your table field names, please.
0
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
to use MAX() or other aggregate functions, you need to use GROUP BY usually...

mySQL="SELECT ume,licenses, max(id) as maxd FROM demo WHERE ume='" &pklkp&"' GROUP BY ume, licenses"

Open in new window

0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
sasha85Author Commented:
but if i will use group by i some of the records i need will be lost...
* ume,licenses, id are my fields names
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
can you clarify the input data you have, and the requested output, with plain english explanation, please.
0
 
sasha85Author Commented:
the id is auto incriptor
licenses and ume set as Text
0
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
sorry, but does not clarify what you have as DATA, and what you want to be returned as DATA.
you posted STRUCTURE.
0
 
sasha85Author Commented:
for example:

    id          ume           licenses
     1         absd          4234324
     2         sddff          34565
     3         absd          4234324
     4         cfgd          6655555

and the max(id) that i want to recieve is 4

*i need the last id of all table...bo metter the where part...just the maximum id
0
 
sasha85Author Commented:
(select max(id) from demo) as maxd
how can i use it in insert query:

mySQL="INSERT INTO demo (maxid) VALUES (???)"


0
 
Jinesh KamdarCommented:
Does ur demo table really have a column named "maxid" ?
0
 
sasha85Author Commented:
i make this table up...
i just want to know how we put the maximum value to the insert query...

cause that is a syntax errro:

mySQL="INSERT INTO demo (column,maxid) VALUES (1,(select max(id) from demo))"
0
 
Jinesh KamdarConnect With a Mentor Commented:
Try this.

mySQL="INSERT INTO demo (column, maxid) SELECT 1, MAX(id) FROM demo"
0
 
sasha85Author Commented:
and if i want to inser to "column" a pre defined value like '" & someval & "'?
(one pre defined and one maximum)?
0
 
Jinesh KamdarConnect With a Mentor Commented:
Then also, you will have to use the 2nd version, like this.
mySQL = "INSERT INTO demo (column, maxid)
SELECT '" & someval & "', MAX(id) FROM demo"

Open in new window

0
All Courses

From novice to tech pro — start learning today.