Reputation: 335
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
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
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
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
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
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