Skip to content
Advertisement

Tag: mysql

MYSQL Add working days to date

I want to add 5 days to the provided date, but the calculation must skip weekends. I already know how to add 5 days without skipping weekends: SELECT DATE_ADD(`date_field`, INTERVAL 5 DAY) As …

What’s the meaning of RESTRICT in Foreign Keys?

There is 4 cases: (For example I’m talking about ON DELETE) CASCADE: the referencing rows will be deleted automatically along with the referenced ones. SET NULL: the value of referencing record will be set to NULL automatically along with the referenced ones. NO ACTION: There will not be any change in the the referencing rows when the referenced ones are

Why should I use EXISTS() function in MySQL?

I have this query: And when I remove that EXISTS() function, still my code works: So why should I write that? What’s its advantage? Answer In short: EXISTS returns when it finds the first result instead of fetching all matching records (so it is more efficient when there are multiple records matching the criteria) EXISTS is semantically correct. When there

MySQL: How to convert seconds to mm:ss format?

I want to convert seconds to minute : seconds format in sql select statement. At the moment I am using: It works perfectly but it gives me this format of time: hh:mm:ss but I need mm:ss Is it possible to convert seconds into mm:ss format using sql query? Answer If the value is less than an hour, then just do:

How to decide which fields must be indexed in a database table

Explanation I have a table which does not have a primary key (or not even a composite key). The table is for storing the time slots (opening hours and food delivery available hours) of the food shops. Let’s call the table “business_hours” and the main fields are as below. shop_id day (0 – 6, means Sunday – Saturday) type (open,

Select from two tables with group by date

I have two tables: Table t1: So from this table I want to get count field Id for each day. For this I use next query: It’s work good. So next table is t2. To select data by date from this table I use next query: It’s also work good. So my purpose is merge these two queries into one

PHP Prepared statement bind_param() error

Many people on stackoverflow has had this problem, but i still cannot spot the mistake This is the error: This is the lines of code: Answer After every mysqli or PDO function that COULD return a bad/failed status you must test for that possibility. The error Fatal error: Call to a member function bind_param() on boolean says it all. $insertpost

Advertisement