|
-
Jun 4th, 2007, 12:46 PM
#1
Thread Starter
Frenzied Member
[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...
-
Jun 4th, 2007, 12:48 PM
#2
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.
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Jun 4th, 2007, 01:20 PM
#3
Thread Starter
Frenzied Member
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?
-
Jun 4th, 2007, 01:23 PM
#4
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)
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Jun 4th, 2007, 01:44 PM
#5
Thread Starter
Frenzied Member
Re: Need a little help with SQL query
Thanks, that worked perfect...
-
Jun 4th, 2007, 01:48 PM
#6
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.
Sometimes the Programmer
Sometimes the DBA
Mazz1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|