[RESOLVED] Need a little help with SQL query
Is there a way to get the values in all the columns of a row when I use the max() function on one of the columns? ie. if I have a column in my table called "index" & I do select max(index) from myTable it just returns the value in that column. I need all the values in the row where index is "max". What's the easiest way to do this? Thanks...
Re: Need a little help with SQL query
A sub qerury like this:
Select * From myTable where Index = (select max(index) From mytable)
I do hope that index is not the name of the field in the database.
Re: Need a little help with SQL query
OK, that worked. Thanks. Now lets try something a little different. Suppose I want to select the row where 'index' is max from among the rows where 'order_num' = something. For example, in my table I have 10 rows where 'order_num' is the same value, now I want to get the 1 row of those 10 where 'index' is max. I hope I explained that well enough.
And, no, my column name is not 'index', I just used that as an example. But I gather that using 'index' is bad practice?
Re: Need a little help with SQL query
Yes index is a Reserved word and all reserved words need to be avoided like the plague when naming fields.
What I think you are asking is like this:
Select * From myTable where Index = (select max(index) From mytable Where order_num = Something here)
Re: Need a little help with SQL query
Thanks, that worked perfect...
Re: Need a little help with SQL query
If that resolves you issued could you please use the thread tools and mark the issuse resolved.