Found 4219 Articles for MySQLi

Can we add minutes to VARCHAR datetime records while applying INSERT statement in MySQL?

AmitDiwan
Updated on 06-Apr-2020 13:33:31

126 Views

Yes, we can add minutes while inserting values in a table.Let us first create a table. Here, we have a column with VARCHAR records where inmysql> create table DemoTable2026    -> (    -> ArrivalTime varchar(20)    -> ); Query OK, 0 rows affected (0.40 sec)Insert some records in the table using insert command. We are first converting the VARCHAR date and then adding minutes −mysql> insert into DemoTable2026 values(date_add(str_to_date('2017-12-01 11:34:45', '%Y-%m-%d %H:%i:%s'), INTERVAL 10 MINUTE)); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable2026 values(date_add(str_to_date('2015-01-31 10:00:00', '%Y-%m-%d %H:%i:%s'), INTERVAL 5 MINUTE)); Query OK, 1 row affected ... Read More

Find and replace a part of URL records in MySQL?

AmitDiwan
Updated on 06-Apr-2020 13:31:49

742 Views

The simplest way to replace records is using MySQL REPLACE() −mysql> create table DemoTable2025    -> (    -> URL text    -> ); Query OK, 0 rows affected (0.88 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2025 values('http=//www.facebook.com'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable2025 values('http=//www.google.com'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable2025 values('http=//www.gmail.com'); Query OK, 1 row affected (0.26 sec)Display all records from the table using select statement −mysql> select *from DemoTable2025;This will produce the following output −+-------------------------+ | URL ... Read More

Return a list from different rows into a single field with MySQL

AmitDiwan
Updated on 06-Apr-2020 13:29:37

665 Views

For this, use GROUP_CONCAT(). Let us first create a table −mysql> create table DemoTable2024    -> (    -> SubjectName varchar(20),    -> StudentName varchar(20)    -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2024 values('MySQL', 'Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2024 values('MySQL', 'David'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2024 values('MongoDB', 'Bob'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable2024 values('Java', 'Sam'); Query OK, 1 row affected (0.18 sec) mysql> ... Read More

MySQL regular expression to update a table with column values including string, numbers and special characters

AmitDiwan
Updated on 06-Apr-2020 13:26:18

587 Views

For this, use UPDATE command along with REGEXP. Let us first create a table −mysql> create table DemoTable2023    -> (    -> StreetNumber varchar(100)    -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2023 values('7'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable2023 values('1'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2023 values('AUS-100'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable2023 values('US-101'); Query OK, 1 row affected (0.11 sec)Display all records from the table using ... Read More

How do I insert multiple values in a column with a single MySQL query?

AmitDiwan
Updated on 06-Apr-2020 13:24:43

1K+ Views

To insert multiple values in a column, the syntax is as follows −insert into yourTableName values(yourValue1), (yourValue2), ..........N;To understand the above syntax, let us create a table −mysql> create table DemoTable2022    -> (    -> Department varchar(100)    -> ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2022 values('Computer Science'), ('Information Technology'), ('Civil'), ('Mechanical'), ('Electronics'), ('Electrical'); Query OK, 6 rows affected (0.46 sec) Records: 6 Duplicates: 0 Warnings: 0Display all records from the table using select statement −mysql> select *from DemoTable2022;This will produce the following ... Read More

Insert data from one schema to another in MySQL?

AmitDiwan
Updated on 06-Apr-2020 13:20:37

981 Views

To insert data from one scheme to another, the syntax is as follows. Here, we have two databases “yourDatabaseName1” and “yourDatabaseName2” −insert into yourDatabaseName2.yourTableName2 select *from yourDatabaseName1.yourTableName1;To understand the above syntax, let us create a table. We are creating a table in database “web” −mysql> create table DemoTable2020    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2020 values(101, 'Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2020 values(102, 'David'); Query OK, 1 ... Read More

MySQL: update field with Group By?

AmitDiwan
Updated on 06-Apr-2020 13:12:36

666 Views

To update field with GROUP BY, use ORDER BY LIMIT with UPDATE command −mysql> create table DemoTable2018    -> (    -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> EmployeeName varchar(20),    -> EmployeeSalary int    -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2018(EmployeeName, EmployeeSalary) values('Chris', 10000); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable2018(EmployeeName, EmployeeSalary) values('David', 12560); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable2018(EmployeeName, EmployeeSalary) values('Chris', 25400); Query OK, 1 row affected (0.09 sec)Display all ... Read More

MySQL query to update all records to capitalize only the first letter and set all others in lowercase

AmitDiwan
Updated on 06-Apr-2020 13:07:21

686 Views

Let us first create a table −mysql> create table DemoTable2017    -> (    -> Name text    -> ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2017 values('JOHN SMITH, MYSQL'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2017 values('DAVID MILLER, MONGODB'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2017 values('CHRIS BROWN, JAVA'); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select *from DemoTable2017;This will produce the following output −+----------------------+ | Name   ... Read More

MySQL query to concatenate records with similar corresponding ids in a single row separated by a special character

AmitDiwan
Updated on 06-Apr-2020 13:04:16

217 Views

For this, you can use CONCAT_WS() along with GROUP_CONCAT(). Let us first create amysql> create table DemoTable2016    -> (    -> UserId int,    -> UserName varchar(20)    -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2016 values(1, 'Chris'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable2016 values(2, 'Bob'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable2016 values(1, 'David'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2016 values(2, 'Carol'); Query OK, 1 row affected (0.12 ... Read More

Fetch a specific record using a single MySQL query with AND & OR operator

AmitDiwan
Updated on 06-Apr-2020 14:00:14

109 Views

Let us first create a table −mysql> create table DemoTable2015    -> (    -> StudentId int,    -> StudentName varchar(20),    -> StudentCountryName varchar(20) -> ); Query OK, 0 rows affected (1.20 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2015 values(1, 'Chris', 'US'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable2015 values(2, 'Bob', 'UK'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2015 values(3, 'David', 'AUS'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable2015 values(4, 'Robert', 'US'); Query OK, 1 ... Read More

Advertisements