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

  • Home
  • SEARCH
  • 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 8063745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:08:48+00:00 2026-06-05T11:08:48+00:00

I have a same result when I execute both queries from different functions. I

  • 0

I have a same result when I execute both queries from different functions. I just wanted to know which query is optimized or logically correct (see query 1 and 2 below).

I get monthly data with respect to sale.purchase_date

Query 1

SELECT sales.purchase_date FROM `sales` 
WHERE sales.purchase_date LIKE  '2012-06-%';

Query 2

SELECT sales.purchase_date FROM `sales` 
WHERE MONTH(sales.purchase_date) = '6' AND YEAR(sales.purchase_date) = '2012';
  • 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-05T11:08:50+00:00Added an answer on June 5, 2026 at 11:08 am

    Both of those require you to do a table scan because you need to examine the purchase_date to see if the row will be in and can’t use an index. I suggest you use a BETWEEN query so you can make use of any index on purchase_date:

    WHERE sales.purchase_date BETWEEN '2012-06-01' AND '2012-06-30'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an WCF application which uses NHibernate to query data from the database.
I have stored procedure which I will execute its result and pass it into
I have a very simple yes no question: should static methods have same result
Is it possible to have same table name on different schema with different data
Can we have same delegate for two events ? which have same number of
Html text box should have same font size for both upper and lower case
Is it possible to have same hashcode for different strings using java's hashcode function?or
I have a query that I want to execute that fastest possible. Here it
I have to execute a SQL made from some users and show its results.
I have a very complex Linq to SQL query that returns a result set

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.