Electronic Circuit
Electronic Circuit

Reputation: 335

How to make max(date) in the where clause condition

I am using this query to query out data only from the latest date

SELECT total_personnel 
FROM fcponc
WHERE day_date=
   SELECT MAX(day_date) FROM fcponc;

but there is an error -- please advise how to correct it

SELECT total_personnel 
FROM fcponc 
WHERE day_date=
   SELECT MAX(day_date) FROM fcponc;

Upvotes: 0

Views: 939

Answers (5)

H.K
H.K

Reputation: 183

I think the following will be faster:

SELECT total_personnel  
FROM fact_personnel_on_site_category  
order by day_date desc  
limit 1;  

Upvotes: 0

KP.
KP.

Reputation: 393

You need have brackets surrounding your inner query

SELECT total_personnel 
FROM fcponc 
WHERE day_date = 
    (SELECT MAX(day_date) FROM fcponc);

Upvotes: 1

Sunil kumar
Sunil kumar

Reputation: 771

You have to use (__) brackets to make second query separate.

SELECT column_name
FROM table_name
WHERE date_column = (
SELECT MAX( date_column )
FROM table_name
)

Upvotes: 0

dhS
dhS

Reputation: 3694

SELECT total_personnel 
FROM fact_personnel_on_site_category 
WHERE day_date=
   (SELECT MAX(day_date) FROM fact_personnel_on_site_category);

Please make your inner query in brackets ... is it working for you ?

Upvotes: 1

JanR
JanR

Reputation: 6132

You need to put your sub-query in parenthesis:

SELECT total_personnel 
FROM fact_personnel_on_site_category 
WHERE day_date= ( SELECT MAX(day_date) FROM fact_personnel_on_site_category);

Upvotes: 1

Related Questions