|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
sql select help required
I have a table T1 with the following columns
( A Char, B char, C Char, D char, E Date) I have the data for A and B and I want to retrieve the records with the maximum date, The columns C and D will repeat for a combination of A, B. I can write a sql with a subquery like this , but due to performance reasons I dont prefer a subquery Select C, D, E from T where A = n and B= m and T = ( select Max(E) from T where A= n and B= m) Performace is very important for this query. Please help. Thanks, Sumanb |
|
#2
|
||||
|
||||
|
maybe something like:
SELECT C, D, E FROM T1 WHERE A='n' AND B='m', ORDER BY E DESC LIMIT 1; this will order the items that apply (A=n and B=m), with the biggest on top, then only take the first (one with the highest date) Alternatively, if what you mean by Quote:
SELECT C, D, MAX(E) FROM T1 WHERE A='n' AND B='m' GROUP BY a, b); only use this if that's true though, ontherwise you'll get wrong results. |
|
#3
|
|||
|
|||
|
Hi Sumanb
I prefer doing this query using INNER JOIN. It will be much quicker Raj Quote:
|
![]() |
| Viewing: Dev Articles Community Forums > Databases > General SQL Development > sql select help required |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|