meks
meks

Reputation: 807

how to select one date before expiration date

I'm trying to came up with a query which will allow me to select data with at list one day before the expiration date

I Tried this one. But also doesn't work:

SELECT code, prod_name, price, expdate, ROUND((expdate - sysdate), 5) 
from items_info 
WHERE (SELECT ROUND((expdate - sysdate), 5) from items_info) > 1 ;

Can anybody tell me what is wrong with my query or tell me how can I come ope with a different one which will satisfy the condition.

Upvotes: 0

Views: 54

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270503

If you are using Oracle, try this:

SELECT code, prod_name, price, expdate, ROUND((expdate - sysdate), 5) 
from items_info 
WHERE expdate >= trunc(SYSDATE + 1);

The problem with your query (as originally written) was the use of a MySQL function.

The problem with your query as currently written is that the subquery will return more than one row, in most cases, and you'll get an error. Then, even if the subquery works, you'll get either all rows (because the where clause is true) or no rows (because the subquery is false).

Upvotes: 2

Related Questions