Found 4381 Articles for MySQL

Subtracting a number from a single MySQL column value?

AmitDiwan
Updated on 11-Nov-2019 09:23:28

770 Views

For this, just update the table and subtract. Let us first create a table −mysql> create table DemoTable1372    -> (    -> Value int    -> ); Query OK, 0 rows affected (0.77 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1372 values(500); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1372 values(100); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable1372 values(900); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1372 values(1000); Query OK, 1 row affected (0.32 sec)Display all records from the table using select statement −mysql> ... Read More

Get values from all rows and display it a single row separated by comma with MySQL

AmitDiwan
Updated on 11-Nov-2019 09:21:18

2K+ Views

For this, use GROUP_CONCAT(). Do not use GROUP BY clause, since GROUP_CONTACT() is a better and quick solution.Let us first create a table −mysql> create table DemoTable1371    -> (    -> Id int,    -> CountryName varchar(40)    -> ); Query OK, 0 rows affected (0.89 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1371 values(100, 'US'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1371 values(100, 'UK'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1371 values(101, 'AUS'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable1371 values(101, ... Read More

Get the sum only from specific cells in MySQL?

AmitDiwan
Updated on 11-Nov-2019 09:19:59

138 Views

For only specific cells, set a condition with WHERE and use aggregate function SUM() to add. Let us first create a table −mysql> create table DemoTable1370    -> (    -> StudentName varchar(20),    -> Marks int    -> ); Query OK, 0 rows affected (0.87 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1370 values('Adam Smith', 56); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1370 values('Chris Brown', 67); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1370 values('Adam Smith', 69); Query OK, 1 row affected (0.20 sec) mysql> insert into ... Read More

MySQL number-string formatting to pad zeros on the left of a string with numbers after a slash

AmitDiwan
Updated on 08-Nov-2019 11:20:41

299 Views

Let us first create a table −mysql> create table DemoTable1369     -> (     -> BatchId varchar(20)     -> ); Query OK, 0 rows affected (0.46 sec)Insert some records in the table using insert command. We have inserted numbers here separated by a slash −mysql> insert into DemoTable1369 values('19/5'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1369 values('19/78'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1369 values('19/567'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1369 values('19/1234'); Query OK, 1 row affected (0.11 sec)Display all records from the table ... Read More

Implement numbering in MySQL GROUP_CONCAT

AmitDiwan
Updated on 08-Jul-2020 11:58:17

536 Views

Let us first create a table −mysql> create table DemoTable1627     -> (     -> FirstName varchar(20),     -> LastName varchar(20)     -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command.mysql> insert into DemoTable1627 values('John', 'Smith'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1627 values('John', 'Doe'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1627 values('Adam', 'Smith'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1627 values('Carol', 'Taylor'); Query OK, 1 row affected (0.08 sec)Display all records from the table using ... Read More

MySQL query to append a number of stars based on string length?

AmitDiwan
Updated on 08-Nov-2019 11:17:51

237 Views

For this, you can use RPAD(). Let us first create a table −mysql> create table DemoTable1626     -> (     -> Name varchar(20)     -> ); Query OK, 0 rows affected (0.37 sec)Insert some records in the table using insert command −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 statement −mysql> select * from DemoTable1626; This will produce the following output −+--------+ ... Read More

Adding dash between spaces in field name in MySQL?

AmitDiwan
Updated on 08-Nov-2019 11:16:51

425 Views

You can use REPLACE() for this. Let us first create a table −mysql> create table DemoTable1625     -> (     -> FullName varchar(20)     -> ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1625 values('John Doe'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1625 values('Adam Smith'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1625 values('John Smith'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1625 values('Carol Taylor'); Query OK, 1 row affected (0.14 sec)Display all records from the ... Read More

SELECT * WHERE var == [one of many alternatives] in MySQL?

AmitDiwan
Updated on 08-Nov-2019 11:15:50

262 Views

Use IN() for select * where var== [one of many alternatives]. Let us first create a table −mysql> create table DemoTable1624     -> (     -> ClientId int,     -> ClientName varchar(20)     -> ); Query OK, 0 rows affected (0.39 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1624 values(101, 'Chris Brown'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable1624 values(102, 'David Miller'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1624 values(103, 'John Smith'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1624 ... Read More

How to sort an alphanumeric column with different lengths in MySQL?

AmitDiwan
Updated on 08-Nov-2019 11:14:54

172 Views

Let us first create a table −mysql> create table DemoTable1623     -> (     -> StudentCode varchar(20)     -> ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1623 values('STU-MIT-143'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1623 values('STU-MIT-10'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1623 values('STU-MIT-150'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1623 values('STU-MIT-148'); Query OK, 1 row affected (0.22 sec)Display all records from the table using select statement −mysql> select * from DemoTable1623; This ... Read More

How to search for the exact string value in MySQL?

AmitDiwan
Updated on 08-Nov-2019 11:10:21

182 Views

To search for the exact string value, use the concept of COLLATE. Let us first create a table −mysql> create table DemoTable1620     -> (     -> Subject varchar(20)     -> ); Query OK, 0 rows affected (0.42 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1620 values('mysql'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1620 values('MySql'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1620 values('mYSQL'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1620 values('MySQL'); Query OK, 1 row affected (0.26 sec) mysql> insert ... Read More

Advertisements