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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Cornelia YoderArtistCommented:
Show your table field names, please.
0
Guy Hengel [angelIII / a3]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
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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]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
Guy Hengel [angelIII / a3]Billing EngineerCommented:
ok:
mySQL="SELECT ume,licenses, (select max(id) from demo) as maxd FROM demo WHERE ume='" &pklkp&"'"

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 KamdarCommented:
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 KamdarCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.