N
N
Nodir Malikov2020-12-21 16:41:45
SQL
Nodir Malikov, 2020-12-21 16:41:45

Why is SQL query returning empty?

There is a table - products in which there are many products
I request the highest model number Printer

select model, type
from product
where type = 'Printer' and model=(select max(model) from product)


but the query returns 0 rows, why is that?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nodir Malikov, 2020-12-21
@Fayo

select type, max(model)
from product
group by type

B
BasiC2k, 2020-12-21
@BasiC2k

At you model is a number? The aggregate function max only applies to numbers. What does the select max(model) from product
query return to you?

S
Sergey Pankov, 2020-12-21
@trapwalker

You have the maximum model selected among all products: and it may not be a printer. And then you look for a printer with just that model. Apparently there is no such thing. select max(model) from product

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question