PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, February 20, 2022

[FIXED] Select rows from table inserted through the past week

 February 20, 2022     innodb, phpmyadmin, sql     No comments   

Issue

I need to select all rows added in the last week in the database.

This is for a "Top 5" page which should show the most sold products over the past 7 days. I tried:

SELECT order_id
FROM orders
WHERE order_date BETWEEN DATE_ADD(week,-1,CURRENT_DATE) AND NOW() 

which returns this error:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-1,CURRENT_DATE) AND NOW() LIMIT 0, 25' at line 1

Other things I have tried were simply the same query but with other syntax not working on this sql server.


Solution

you just need below

SELECT order_id FROM orders 
WHERE order_date >= NOW() - INTERVAL 1 WEEK


Answered By - Zaynul Abadin Tuhin
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing