Found 4378 Articles for MySQL

Calculating byte values to megabyte (MB) in MySQL?

AmitDiwan
Updated on 06-Apr-2020 13:44:41

1K+ Views

Here, we are taking BIGINT type, since it takes 8 byte signed integer. Let us first create a table with column as BIGINT type −mysql> create table DemoTable2031    -> (    -> ByteValue bigint    -> ); Query OK, 0 rows affected (1.17 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2031 values(1048576); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2031 values(1073741824); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable2031;This will produce the following output −+------------+ | ByteValue | ... Read More

Find maximum value from a VARCHAR column in MySQL

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

1K+ Views

To find maximum value, use MAX() along with CAST(), since the values are of VARCHAR type. Let us first create a table −mysql> create table DemoTable2030    -> (    -> Value varchar(20)    -> ); Query OK, 0 rows affected (0.44 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2030 values('8'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2030 values('1'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable2030 values('10001'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable2030 values('901'); Query OK, 1 row affected ... Read More

Update the content of a specific cell in MySQL

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

461 Views

Let us first create a table −mysql> create table DemoTable2029    -> (    -> Id int,    -> FirstName varchar(20),    -> LastName varchar(20)    -> ); Query OK, 0 rows affected (0.98 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2029 values(1, 'Chris', 'Brown') -> ; Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2029 values(2, 'David', 'Miller'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2029 values(3, 'John', 'Smith'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable2029 values(4, 'John', 'Brown'); Query OK, 1 ... Read More

How to correctly use delimiter in a MySQL stored procedure and insert values?

AmitDiwan
Updated on 06-Apr-2020 13:38:34

354 Views

Let us first create a table −mysql> create table DemoTable2028    -> (    -> StudentFirstName varchar(20),    -> StudentLastName varchar(20)    -> ); Query OK, 0 rows affected (0.87 sec)Here is the query to create a stored procedure and insert values (using delimiter correctly) −mysql> delimiter // mysql> create procedure insert_name(in fname varchar(20), in lname varchar(20))    -> begin    -> insert into DemoTable2028 values(fname, lname);    -> end    -> // Query OK, 0 rows affected (0.17 sec) mysql> delimiter ;Call the stored procedure using CALL command −mysql> call insert_name('Chris', 'Brown'); Query OK, 1 row affected (0.17 sec)Display ... Read More

How to write a valid MySQL query and update with a custom variable?

AmitDiwan
Updated on 06-Apr-2020 13:35:56

338 Views

Let us first create a table −mysql> create table DemoTable2027    -> (    -> UserId int    -> ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2027 values(10); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable2027 values(20); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable2027 values(31); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2027 values(11); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable2027;This will produce ... Read More

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

663 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

Advertisements