Found 4219 Articles for MySQLi

Filter query by current date in MySQL

AmitDiwan
Updated on 22-Aug-2019 10:57:51

1K+ Views

Let us first create a table −mysql> create table DemoTable(DueDate datetime); Query OK, 0 rows affected (0.94 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-07-10 04:20:00'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-07-10 05:10:40'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2019-07-10 09:00:20'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('2019-07-10 10:01:04'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('2019-07-10 12:11:10'); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> ... Read More

Using CREATE TABLE AS statement with UNION of two tables in MySQL

AmitDiwan
Updated on 22-Aug-2019 10:54:03

2K+ Views

For this, you can use UNION. Let us first create a table −mysql> create table DemoTable1(FirstName varchar(1000)); Query OK, 0 rows affected (1.22 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values('John'); Query OK, 1 row affected (0.20 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;This will produce the following output −+-----------+ | FirstName | +-----------+ | John      | +-----------+ 1 row in set (0.02 sec)Here is the query to create second the table −mysql> create table DemoTable2(FirstName varchar(100)); Query OK, 0 rows affected (0.81 sec)Insert some records ... Read More

How to check an empty table already in a MySQL database?

AmitDiwan
Updated on 22-Aug-2019 10:48:25

1K+ Views

To check an empty table is in a database, you need to extract some records from the table. If the table is not empty then the table records would be returned.Let us first create a table −mysql> create table DemoTable(Id int, Name varchar(100), Age int); Query OK, 0 rows affected (0.80 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1001, 'John', 23); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(1002, 'Chris', 21); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(1003, 'David', 22); Query OK, 1 row affected ... Read More

How to order by auto_increment in MySQL?

AmitDiwan
Updated on 22-Aug-2019 10:42:20

450 Views

Let us first create a table −mysql> create table DemoTable(Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(100)); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FirstName) values('Chris'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable(FirstName) values('Robert'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(FirstName) values('David'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(FirstName) values('Mike'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable(FirstName) values('Adam'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(FirstName) values('Carol'); Query OK, ... Read More

Facing difficulty in removing the apostrophe in MySQL stored procedure?

AmitDiwan
Updated on 22-Aug-2019 10:26:46

205 Views

To remove apostrophe, replace it. For this, you can use REPLACE(). Following is the syntax −SET anyVariableName = REPLACE(yourVaribleName , '\'', '');To understand the above syntax, let us create a stored procedure to remove the apostrophe in MySQL −mysql> DELIMITER // mysql> CREATE PROCEDURE remove_Apostrophe(IN Value VARCHAR(200))    BEGIN       SET Value = REPLACE(Value , '\'', '');       SELECT CONCAT("AFTER REMOVING APOSTROPHE THE STRING IS= ", Value);    END    // Query OK, 0 rows affected (0.15 sec) mysql> DELIMITER ;Call the stored procedure using CALL command −mysql> CALL remove_Apostrophe("Introduction to My'SQL");This will produce the following ... Read More

How to get all the MySQL triggers and the triggers for only the current database

AmitDiwan
Updated on 22-Aug-2019 09:02:23

192 Views

To get all the MySQL triggers, following is the syntax −select trigger_schema, trigger_name from information_schema.triggers;Let us implement the above syntax to get all the trigger names along with schema −mysql> select trigger_schema, trigger_name from information_schema.triggers;This will produce the following output −+----------------+---------------------------------+ | TRIGGER_SCHEMA | TRIGGER_NAME                    | +----------------+---------------------------------+ | sys            | sys_config_insert_set_user      | | sys            | sys_config_update_set_user      | | business       | binsertTrigger                  | | business     ... Read More

MySQL isn’t inserting binary data properly? Which datatype should be used?

AmitDiwan
Updated on 22-Aug-2019 08:48:59

491 Views

For this, use BIT data type. Let us first create a table −mysql> create table DemoTable(binaryValue BIT(5)); Query OK, 0 rows affected (0.83 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(15); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output. Now you can see the records aren’t visible −+-------------+ | binaryValue | +-------------+ |             | |           ... Read More

MySQL float data field not accepting every float number? How to fix this?

AmitDiwan
Updated on 22-Aug-2019 08:40:52

142 Views

To get fixed float data type, use DECIMAL(). This will fix the issue of unacceptance. Let us first create a table −mysql> create table DemoTable(Amount DECIMAL(10, 2)); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(2194848.90); Query OK, 1 row affected (0.65 sec) mysql> insert into DemoTable values(90309393.79); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values(8999999.68); Query OK, 1 row affected (0.30 sec) mysql> insert into DemoTable values(90900000.99); Query OK, 1 row affected (0.26 sec)Display all records from the table using select statement −mysql> select ... Read More

MySQL to perform DateTime comparison and find the difference between dates in different columns

AmitDiwan
Updated on 22-Aug-2019 08:34:53

207 Views

For this, use DATEDIFF() function. Let us first create a table −mysql> create table DemoTable(DOB datetime, CurrentDate datetime); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('1995-01-21', CURDATE()); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('1998-11-01', CURDATE()); Query OK, 1 row affected (0.39 sec) mysql> insert into DemoTable values('2000-10-24', CURDATE()); Query OK, 1 row affected (0.22 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+---------------------+---------------------+ | DOB                 ... Read More

How to sort by arbitrary keywords in MySQL?

AmitDiwan
Updated on 22-Aug-2019 08:26:29

150 Views

For this, use the ORDER BY FIELD() ASC. Let us first create a table −mysql> create table DemoTable(Title varchar(100)); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Java'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('C'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('Python'); Query OK, 1 row affected (0.63 sec) mysql> insert into DemoTable values('MongoDB'); Query OK, 1 row affected (0.20 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+---------+ ... Read More

Advertisements