Found 4219 Articles for MySQLi

Create index of three columns in MySQL?

AmitDiwan
Updated on 12-Nov-2019 06:50:10

135 Views

For index, you can use KEY(). Let us first create a −mysql> create table DemoTable1437    -> (    -> StudentId int,    -> StudentName varchar(20),    -> StudentMarks int,    -> StudentAge int    -> ,    -> KEY(StudentId, StudentMarks, StudentAge)    -> ); Query OK, 0 rows affected (0.97 sec)Following is the query to check the description of −mysql> desc DemoTable1437;This will produce the following output −+--------------+-------------+------+-----+---------+-------+ | Field        | Type        | Null | Key | Default | Extra | +--------------+-------------+------+-----+---------+-------+ | StudentId    | int(11)     | YES  | MUL ... Read More

MySQL query to update different fields based on a condition?

AmitDiwan
Updated on 12-Nov-2019 06:46:44

196 Views

Let us first create a −mysql> create table DemoTable1436    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (1.06 sec)Insert some records in the table using insert −mysql> insert into DemoTable1436(Name) values('Chris'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable1436(Name) values('David'); Query OK, 1 row affected (0.40 sec) mysql> insert into DemoTable1436(Name) values('Bob'); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable1436(Name) values('David'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable1436(Name) values('David'); Query OK, 1 row affected ... Read More

MySQL procedure to call multiple procedures?

AmitDiwan
Updated on 12-Nov-2019 06:44:34

909 Views

Let us first see the syntax, wherein we are calling multiple procedures from a stored procedure −DELIMITER // CREATE PROCEDURE yourProcedureName() BEGIN    CALL yourStoredProcedureName1();    CALL yourStoredProcedureName2();    .    .    N END // DELIMITER //Let us implement the above syntax to call multiple stored procedures.Following is the query to create first stored procedure −mysql> DELIMITER // mysql> CREATE PROCEDURE hello_message()    -> BEGIN    -> SELECT 'HELLO WORLD !!';    -> END    -> // Query OK, 0 rows affected (0.19 sec)The query to create second stored procedure is as follows −mysql> CREATE PROCEDURE hi_message()    -> ... Read More

Order dates in MySQL with the format “01 August 2019”?

AmitDiwan
Updated on 12-Nov-2019 06:42:24

62 Views

To display dates like “01 August 2019”, use ORDER BY STR_TO_DATE(). Let us first create a −mysql> create table DemoTable1435    -> (    -> DueDate varchar(60)    -> ); Query OK, 0 rows affected (1.08 sec)Insert some records in the table using insert −mysql> insert into DemoTable1435 values('01 August 2019'); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable1435 values('01 Feb 2018'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1435 values('31 Jan 2017'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1435 values('01 March 2019'); Query OK, 1 row affected (0.11 sec)Display ... Read More

Insert current time minus 1 hour to already inserted date-time records in MYSQL

AmitDiwan
Updated on 12-Nov-2019 06:40:43

716 Views

For subtracting dates, use MySQL DATE_SUB(). Let us first create a −mysql> create table DemoTable1434    -> (    -> ArrivalDatetime datetime    -> ); Query OK, 0 rows affected (3.14 sec)Insert some records in the table using insert −mysql> insert into DemoTable1434 values('2019-09-30 21:10:00'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1434 values('2018-09-30 22:20:40'); Query OK, 1 row affected (0.33 sec) mysql> insert into DemoTable1434 values('2017-09-30 23:10:00'); Query OK, 1 row affected (0.19 sec)Display all records from the table using select −mysql> select * from DemoTable1434;This will produce the following output −+---------------------+ | ArrivalDatetime     ... Read More

Store strings in variables and concatenate them to display them in a single column in MYSQL

AmitDiwan
Updated on 12-Nov-2019 06:39:07

205 Views

For this, use CONCAT_WS() in MySQL. Let us first create a −mysql> create table DemoTable1433    -> (    -> ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ClientFirstName varchar(20),    -> ClientLastName varchar(20)    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert −mysql> insert into DemoTable1433(ClientFirstName, ClientLastName) values('David', 'Miller'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select −mysql> select * from DemoTable1433;This will produce the following output −+----------+-----------------+----------------+ | ClientId | ClientFirstName | ClientLastName | +----------+-----------------+----------------+ |        1 | David   ... Read More

Fetch specific rows from a MySQL table with duplicate column values (names)?

AmitDiwan
Updated on 12-Nov-2019 06:32:50

92 Views

Let us first create a −mysql> create table DemoTable1431    -> (    -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> EmployeeName varchar(20),    -> EmployeeCountryName varchar(20)    -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert −mysql> insert into DemoTable1431(EmployeeName, EmployeeCountryName) values('Adam Smith', 'AUS'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1431(EmployeeName, EmployeeCountryName) values('Chris Brown', 'US'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1431(EmployeeName, EmployeeCountryName) values('John Doe', 'UK'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1431(EmployeeName, EmployeeCountryName) values('Chris Brown', 'AUS'); Query ... Read More

Append special characters to column values in MySQL

AmitDiwan
Updated on 12-Nov-2019 06:29:55

457 Views

Let us first create a −mysql> create table DemoTable1626    -> (    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.37 sec)Insert some records in the table using insert −mysql> insert into DemoTable1626 values('Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1626 values('Bob'); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable1626 values('Robert'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select −mysql> select * from DemoTable1626;This will produce the following output −+--------+ | Name   | +--------+ | Chris  | | Bob    | | ... Read More

Select count of values (Yes, No) with same ids but different corresponding records in MySQL?

AmitDiwan
Updated on 12-Nov-2019 06:28:38

579 Views

For this, you can use SUM() along with CASE statement. Let us first create a −mysql> create table DemoTable1430    -> (    -> EmployeeId int,    -> isMarried ENUM('YES', 'NO')    -> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert −mysql> insert into DemoTable1430 values(1001, 'Yes'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1430 values(1001, 'No'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1430 values(1001, 'Yes'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1430 values(1001, 'Yes'); Query OK, 1 row affected (0.16 sec)Display ... Read More

Fetch date records comparing with the current date’s day and month in MySQL

AmitDiwan
Updated on 12-Nov-2019 06:25:00

114 Views

For this, use MONTH() and DAY(). Let us first create a −mysql> create table DemoTable1429    -> (    -> AnniversaryDate date    -> );Insert some records in the table using insert −mysql> insert into DemoTable1429 values('2019-09-29'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1429 values('2018-09-27'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1429 values('2016-09-28'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1429 values('2015-09-29'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select −mysql> select * from DemoTable1429;This will produce the following output −+-----------------+ | AnniversaryDate ... Read More

Advertisements