SQL Query: Search Row

Argo

Lifer
Apr 8, 2000
10,045
0
0
Please rephrase (or give better example). I don't understand what you need.
 

Jeraden

Platinum Member
Oct 9, 1999
2,518
1
76
I still don't understand what you need.

You mean on the 2nd row which has field3 = 'Min. Val.', you want to find the highest value from fields 5 through 11, just for that particular row?
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Assuming I understand correctly, I'd advise starting by redesigning your data layout, or not doing it in sql (do it in your program code).
 

KB

Diamond Member
Nov 8, 1999
5,401
386
126
Your database violates normal forms 2 and 3. Take a look at database normalization for a better explanation.

I may not understand your problem well but this is how I would do the database:
I would set a table for dates
TimeID------Date
1--------------Oct 1 1948
2--------------Dec 1948

then a table for values linked to the dates
ValueID----TimeFK-------Value
1-------------1--------------12.3
2-------------1--------------2.4
.......

Then you can query max value using SELECT MAX(Value) FROM ValueTable WHERE TimeFK = 1
 

cation555

Member
Jul 1, 2005
32
0
61
Originally posted by: Jeraden
I still don't understand what you need.

You mean on the 2nd row which has field3 = 'Min. Val.', you want to find the highest value from fields 5 through 11, just for that particular row?

Exactly. Any ideas on how to accomplish that?

Yeah, unfortunately this isn't my database---I'm just working with an outdated dataset (I'm aware that the dataset is attrocious from a DB design perspective), I may end up parsing/restructuring the data, but I was jsut trying to save some time now
 

Jeraden

Platinum Member
Oct 9, 1999
2,518
1
76
you could do:

select greatest(field5, field6, field7, field8, field9, field10, field11)
from table
where field3 = 'Min. Val.';

which would work in Oracle at least
 

hans007

Lifer
Feb 1, 2000
20,212
17
81
that is not really a proper database.


if you really wanted to and you had some sort of scripting language at your disposal

you could do smething like, select field5, field7, fieldetc, from TABLE where field3="Min. Val";

and then take whatever array you got and do some calculations in that in the scripting language.

that said that table is ararnged pretty horribly.
 

KEV1N

Platinum Member
Jan 15, 2000
2,932
1
0
Basically, people are saying that your table needs to be transposed. Then, you can use the aggregate function MAX().
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |