Skip to content
Advertisement

Left join on two tables and want to get results from a specific date

I have written a MySQL query to do left join on two tables .

My result query is showing the result I wanted . I just want to know how to further make it limited to specific dates .

The column which I want to sort is user_registered and is showing date in this format 2020-12-17 06:06:05. So how to make it from two different dates . This is my query which I have written down .

SELECT wp_users.user_email,user_nicename,user_registered,freelancerpaid
FROM wp_users
LEFT JOIN wp_posts
ON wp_users.ID = wp_posts.post_author
WHERE wp_posts.post_type="freelancers"
AND wp_users.freelancerpaid="1"

These are the results i am getting from the query So what I want is to get results from the specific dates I can enter .

Thanks in advance .

Advertisement

Answer

If you neet to get Between two dates, use this.

SELECT wp_users.user_email,user_nicename,user_registered,freelancerpaid
FROM wp_users
LEFT JOIN wp_posts
ON wp_users.ID = wp_posts.post_author
WHERE wp_posts.post_type="freelancers"
AND wp_users.freelancerpaid="1"
AND DATE(user_registered) BETWEEN '2020-11-28' AND '2020-11-29'

But if you neet to get lesser or greater than the date, use this. Just change the condition base on what you need.

SELECT wp_users.user_email,user_nicename,user_registered,freelancerpaid
FROM wp_users
LEFT JOIN wp_posts
ON wp_users.ID = wp_posts.post_author
WHERE wp_posts.post_type="freelancers"
AND wp_users.freelancerpaid="1"
AND DATE(user_registered) >= '2020-11-29'
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement