How to take the function max current-date on my query [closed]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-3















I have 2 queries. I want to get MAX date. If I get MAX date my subquery will look like below.



Query 1:



select
tb_format.format
from
tb_format
where
tb_format.id not in
(
select
penyakit.format
from
penyakit
where
penyakit.id_puskesmas =$ id
AND MONTH(penyakit.waktu_upload) = MONTH(CURRENT_DATE)
)


I want to add MAX on this MONTH(penyakit.waktu_upload).



Query 2:



select
tb_format.format
from
tb_format
where
tb_format.id not in
(
select
penyakit.format
from
penyakit
where
penyakit.id_puskesmas =$ id
AND MAX(MONTH(penyakit.waktu_upload)) = MONTH(CURRENT_DATE) -- HERE
)


However, I'm getting an error:



Screenshot 1



Screenshot 2










share|improve this question















closed as unclear what you're asking by Chowkidar Madhur Bhaiya, Vega, jww, Strawberry, Makyen Nov 17 '18 at 8:22


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 1





    Please add some sample data, and expected output. Add details about what are you trying to achieve logically. Based on that information, query can be reformulated in more effective manner. Please go through this link once: Why should I provide an MCVE for what seems to me to be a very simple SQL query?

    – Chowkidar Madhur Bhaiya
    Nov 17 '18 at 7:14











  • Please show the code and/or state the errors. The text on the picture is too small for some people to read. In addition, the text on the image cannot be indexed by search engines for future visitors.

    – jww
    Nov 17 '18 at 7:33


















-3















I have 2 queries. I want to get MAX date. If I get MAX date my subquery will look like below.



Query 1:



select
tb_format.format
from
tb_format
where
tb_format.id not in
(
select
penyakit.format
from
penyakit
where
penyakit.id_puskesmas =$ id
AND MONTH(penyakit.waktu_upload) = MONTH(CURRENT_DATE)
)


I want to add MAX on this MONTH(penyakit.waktu_upload).



Query 2:



select
tb_format.format
from
tb_format
where
tb_format.id not in
(
select
penyakit.format
from
penyakit
where
penyakit.id_puskesmas =$ id
AND MAX(MONTH(penyakit.waktu_upload)) = MONTH(CURRENT_DATE) -- HERE
)


However, I'm getting an error:



Screenshot 1



Screenshot 2










share|improve this question















closed as unclear what you're asking by Chowkidar Madhur Bhaiya, Vega, jww, Strawberry, Makyen Nov 17 '18 at 8:22


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 1





    Please add some sample data, and expected output. Add details about what are you trying to achieve logically. Based on that information, query can be reformulated in more effective manner. Please go through this link once: Why should I provide an MCVE for what seems to me to be a very simple SQL query?

    – Chowkidar Madhur Bhaiya
    Nov 17 '18 at 7:14











  • Please show the code and/or state the errors. The text on the picture is too small for some people to read. In addition, the text on the image cannot be indexed by search engines for future visitors.

    – jww
    Nov 17 '18 at 7:33














-3












-3








-3








I have 2 queries. I want to get MAX date. If I get MAX date my subquery will look like below.



Query 1:



select
tb_format.format
from
tb_format
where
tb_format.id not in
(
select
penyakit.format
from
penyakit
where
penyakit.id_puskesmas =$ id
AND MONTH(penyakit.waktu_upload) = MONTH(CURRENT_DATE)
)


I want to add MAX on this MONTH(penyakit.waktu_upload).



Query 2:



select
tb_format.format
from
tb_format
where
tb_format.id not in
(
select
penyakit.format
from
penyakit
where
penyakit.id_puskesmas =$ id
AND MAX(MONTH(penyakit.waktu_upload)) = MONTH(CURRENT_DATE) -- HERE
)


However, I'm getting an error:



Screenshot 1



Screenshot 2










share|improve this question
















I have 2 queries. I want to get MAX date. If I get MAX date my subquery will look like below.



Query 1:



select
tb_format.format
from
tb_format
where
tb_format.id not in
(
select
penyakit.format
from
penyakit
where
penyakit.id_puskesmas =$ id
AND MONTH(penyakit.waktu_upload) = MONTH(CURRENT_DATE)
)


I want to add MAX on this MONTH(penyakit.waktu_upload).



Query 2:



select
tb_format.format
from
tb_format
where
tb_format.id not in
(
select
penyakit.format
from
penyakit
where
penyakit.id_puskesmas =$ id
AND MAX(MONTH(penyakit.waktu_upload)) = MONTH(CURRENT_DATE) -- HERE
)


However, I'm getting an error:



Screenshot 1



Screenshot 2







php mysql subquery






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '18 at 8:21









kit

1,10431017




1,10431017










asked Nov 17 '18 at 6:52









Adhik MulatAdhik Mulat

35




35




closed as unclear what you're asking by Chowkidar Madhur Bhaiya, Vega, jww, Strawberry, Makyen Nov 17 '18 at 8:22


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as unclear what you're asking by Chowkidar Madhur Bhaiya, Vega, jww, Strawberry, Makyen Nov 17 '18 at 8:22


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 1





    Please add some sample data, and expected output. Add details about what are you trying to achieve logically. Based on that information, query can be reformulated in more effective manner. Please go through this link once: Why should I provide an MCVE for what seems to me to be a very simple SQL query?

    – Chowkidar Madhur Bhaiya
    Nov 17 '18 at 7:14











  • Please show the code and/or state the errors. The text on the picture is too small for some people to read. In addition, the text on the image cannot be indexed by search engines for future visitors.

    – jww
    Nov 17 '18 at 7:33














  • 1





    Please add some sample data, and expected output. Add details about what are you trying to achieve logically. Based on that information, query can be reformulated in more effective manner. Please go through this link once: Why should I provide an MCVE for what seems to me to be a very simple SQL query?

    – Chowkidar Madhur Bhaiya
    Nov 17 '18 at 7:14











  • Please show the code and/or state the errors. The text on the picture is too small for some people to read. In addition, the text on the image cannot be indexed by search engines for future visitors.

    – jww
    Nov 17 '18 at 7:33








1




1





Please add some sample data, and expected output. Add details about what are you trying to achieve logically. Based on that information, query can be reformulated in more effective manner. Please go through this link once: Why should I provide an MCVE for what seems to me to be a very simple SQL query?

– Chowkidar Madhur Bhaiya
Nov 17 '18 at 7:14





Please add some sample data, and expected output. Add details about what are you trying to achieve logically. Based on that information, query can be reformulated in more effective manner. Please go through this link once: Why should I provide an MCVE for what seems to me to be a very simple SQL query?

– Chowkidar Madhur Bhaiya
Nov 17 '18 at 7:14













Please show the code and/or state the errors. The text on the picture is too small for some people to read. In addition, the text on the image cannot be indexed by search engines for future visitors.

– jww
Nov 17 '18 at 7:33





Please show the code and/or state the errors. The text on the picture is too small for some people to read. In addition, the text on the image cannot be indexed by search engines for future visitors.

– jww
Nov 17 '18 at 7:33












1 Answer
1






active

oldest

votes


















0














You can't have MAX in a WHERE clause, you can have it in a HAVING clause (this explains the difference a bit more)...



  select
penyakit.format
from
penyakit
where
penyakit.id_puskesmas =$ id
group by
penyakit.format
having
MAX(MONTH(penyakit.waktu_upload)) = MONTH(CURRENT_DATE)


There has to be a GROUP BY clause and this gives the basis for what the MAX operates over, the HAVING clause is almost a WHERE clause for the GROUP BY.



Not sure what the $ id is so I've just copied from your original code, but this will need to be corrected.






share|improve this answer
























  • thanks . i dont know MAX cant used clause where . very helpfull . thanks you brother

    – Adhik Mulat
    Nov 17 '18 at 13:33


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You can't have MAX in a WHERE clause, you can have it in a HAVING clause (this explains the difference a bit more)...



  select
penyakit.format
from
penyakit
where
penyakit.id_puskesmas =$ id
group by
penyakit.format
having
MAX(MONTH(penyakit.waktu_upload)) = MONTH(CURRENT_DATE)


There has to be a GROUP BY clause and this gives the basis for what the MAX operates over, the HAVING clause is almost a WHERE clause for the GROUP BY.



Not sure what the $ id is so I've just copied from your original code, but this will need to be corrected.






share|improve this answer
























  • thanks . i dont know MAX cant used clause where . very helpfull . thanks you brother

    – Adhik Mulat
    Nov 17 '18 at 13:33
















0














You can't have MAX in a WHERE clause, you can have it in a HAVING clause (this explains the difference a bit more)...



  select
penyakit.format
from
penyakit
where
penyakit.id_puskesmas =$ id
group by
penyakit.format
having
MAX(MONTH(penyakit.waktu_upload)) = MONTH(CURRENT_DATE)


There has to be a GROUP BY clause and this gives the basis for what the MAX operates over, the HAVING clause is almost a WHERE clause for the GROUP BY.



Not sure what the $ id is so I've just copied from your original code, but this will need to be corrected.






share|improve this answer
























  • thanks . i dont know MAX cant used clause where . very helpfull . thanks you brother

    – Adhik Mulat
    Nov 17 '18 at 13:33














0












0








0







You can't have MAX in a WHERE clause, you can have it in a HAVING clause (this explains the difference a bit more)...



  select
penyakit.format
from
penyakit
where
penyakit.id_puskesmas =$ id
group by
penyakit.format
having
MAX(MONTH(penyakit.waktu_upload)) = MONTH(CURRENT_DATE)


There has to be a GROUP BY clause and this gives the basis for what the MAX operates over, the HAVING clause is almost a WHERE clause for the GROUP BY.



Not sure what the $ id is so I've just copied from your original code, but this will need to be corrected.






share|improve this answer













You can't have MAX in a WHERE clause, you can have it in a HAVING clause (this explains the difference a bit more)...



  select
penyakit.format
from
penyakit
where
penyakit.id_puskesmas =$ id
group by
penyakit.format
having
MAX(MONTH(penyakit.waktu_upload)) = MONTH(CURRENT_DATE)


There has to be a GROUP BY clause and this gives the basis for what the MAX operates over, the HAVING clause is almost a WHERE clause for the GROUP BY.



Not sure what the $ id is so I've just copied from your original code, but this will need to be corrected.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 17 '18 at 7:33









Nigel RenNigel Ren

29k62034




29k62034













  • thanks . i dont know MAX cant used clause where . very helpfull . thanks you brother

    – Adhik Mulat
    Nov 17 '18 at 13:33



















  • thanks . i dont know MAX cant used clause where . very helpfull . thanks you brother

    – Adhik Mulat
    Nov 17 '18 at 13:33

















thanks . i dont know MAX cant used clause where . very helpfull . thanks you brother

– Adhik Mulat
Nov 17 '18 at 13:33





thanks . i dont know MAX cant used clause where . very helpfull . thanks you brother

– Adhik Mulat
Nov 17 '18 at 13:33





Popular posts from this blog

Bressuire

Vorschmack

Quarantine