Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8881673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:23:33+00:00 2026-06-14T20:23:33+00:00

Following is mysql query in which i am detecteing if the current (All)month&(in current)year

  • 0

Following is mysql query in which i am detecteing if the current (All)month&(in current)year exist in the database date column or not. Query is working fine but its running for every row of the table separately and returning all the number of rows present in the table with the specific match for that row. What i wanna do is that the following query should return single row and tells if the given date exist (anywhere in date column) in the table or not . Kindly let me know how can i modify the following query to do this. Thanks

SELECT 
IF(DATE_FORMAT(FROM_UNIXTIME(dt_note_created),'%Y%m') =  CONCAT((DATE_FORMAT(NOW(),'%Y')),'01'),1,0) as jan,
IF(DATE_FORMAT(FROM_UNIXTIME(dt_note_created),'%Y%m') =  CONCAT((DATE_FORMAT(NOW(),'%Y')),'02'),1,0) as feb,
IF(DATE_FORMAT(FROM_UNIXTIME(dt_note_created),'%Y%m') =  CONCAT((DATE_FORMAT(NOW(),'%Y')),'03'),1,0) as mar,
IF(DATE_FORMAT(FROM_UNIXTIME(dt_note_created),'%Y%m') =  CONCAT((DATE_FORMAT(NOW(),'%Y')),'04'),1,0) as apr,
IF(DATE_FORMAT(FROM_UNIXTIME(dt_note_created),'%Y%m') =  CONCAT((DATE_FORMAT(NOW(),'%Y')),'05'),1,0) as may,
IF(DATE_FORMAT(FROM_UNIXTIME(dt_note_created),'%Y%m') =  CONCAT((DATE_FORMAT(NOW(),'%Y')),'06'),1,0) as jun,
IF(DATE_FORMAT(FROM_UNIXTIME(dt_note_created),'%Y%m') =  CONCAT((DATE_FORMAT(NOW(),'%Y')),'07'),1,0) as jul,
IF(DATE_FORMAT(FROM_UNIXTIME(dt_note_created),'%Y%m') =  CONCAT((DATE_FORMAT(NOW(),'%Y')),'08'),1,0) as aug,
IF(DATE_FORMAT(FROM_UNIXTIME(dt_note_created),'%Y%m') =  CONCAT((DATE_FORMAT(NOW(),'%Y')),'09'),1,0) as sep,
IF(DATE_FORMAT(FROM_UNIXTIME(dt_note_created),'%Y%m') =  CONCAT((DATE_FORMAT(NOW(),'%Y')),'10'),1,0) as oct,
IF(DATE_FORMAT(FROM_UNIXTIME(dt_note_created),'%Y%m') =  CONCAT((DATE_FORMAT(NOW(),'%Y')),'11'),1,0) as nov,
IF(DATE_FORMAT(FROM_UNIXTIME(dt_note_created),'%Y%m') =  CONCAT((DATE_FORMAT(NOW(),'%Y')),'12'),1,0) as decb
FROM Notes

Output:

jan | feb | Mar ....and so on... | nov | dec
 0     1     1                      0     1

0 and 1 are flags which are telling if the monthandyear exist in the whole column of date or not
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:23:34+00:00Added an answer on June 14, 2026 at 8:23 pm

    I’m not sure if I understood correctly, but if u only want to check if there is at least one date in your column matching current month and year, try

    SELECT COUNT(*) 
    FROM date
    WHERE MONTH(dt_note_created) = MONTH(Now()) 
      AND YEAR(dt_note_created) = YEAR(Now()) 
    

    this will return 0 if there is no such date and otherwise the number of dates in total.

    Try

    SELECT DISTINCT MONTH(dt_note_created)
    FROM date
    WHERE YEAR(dt_note_created) = YEAR(Now())
    

    to get a list of the differnet month included in your date column.

    it returns something like (for dates in Jan, Feb, Aug, Nov):

    1
    2
    8
    11
    

    And as long as this number is less than 12 there is not at least one date in each month.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to query a mysql table which places its date in the following
I have the following MYSQL query which when executed shows me all the invalid
I have the following MySQL query which gets all the bookings for an agent,
I have the following mysql query which I am running with php like so.
I have the following mysql query, which is producing a list of entries by
I currently have the following MySQL query, which I would like to include in
We have a query(mysql) which returns data in the following format of alphabets followed
I am using the following MySQL query which is working fine, I mean giving
I currently have the following MySQL query, which executes fine without any errors: SELECT
I have the following MySQL query, which produces the result I want: SELECT `l`.`status`,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.