Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ORACLE Database Query to retrun all rows exception the one with the largest valu

ID: 3805172 • Letter: O

Question

ORACLE Database Query to retrun all rows exception the one with the largest value in a field.

Table contain the following:

name1, age, dob, address

john doe1, 45, 12-1-75, 123 somewhere USA

john doe2, 55, 12-1-65, 456 somewhere USA

john doe3, 35, 12-1-85, 789 somewhere USA

john doe4, 25, 12-1-95, 012, somewhere USA

how do I write an Oracle SQL query to list all the rows with the exception of the one with the largest age (55), but because its a database I don't know which row has the largest age, the query has to figure it out.

Explanation / Answer

Answer:

select * from Tablename where age < (select max(age) from Tablename);

This query will give you all rows except the largest age row.

select max(age) from Tablename this is a subquery which will return the largest age in the table so here we are fetching all ros except this in min query using where condition.