AmitDiwan has Published 10744 Articles

Remove specific word in a comma separated string with MySQL

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:54:08

1K+ Views

Let us first create a table −mysql> create table DemoTable836(FirstName SET('John', 'Chris', 'Adam')); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable836 values('John, Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable836 values('John, Chris, Adam'); Query OK, ... Read More

Can we insert values without mentioning the column name in MySQL?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:52:52

676 Views

Yes, we can insert values without mentioning the column name using the following syntax −insert into yourTableName values(yourValue1, yourValue2, yourValue3, .....N);Let us first create a table. Here, we have set Id as NOT NULL −mysql> create table DemoTable862(    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FirstName varchar(100) , ... Read More

How to concatenate two column values into a single column with MySQL. The resultant column values should be separated by hyphen

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:51:14

1K+ Views

Let us first create a table −mysql> create table DemoTable835(    CountryCode int,    CountryName varchar(100) ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable835 values(100, 'US'); Query OK, 1 row affected (0.36 sec) mysql> insert into DemoTable835 values(101, ... Read More

MySQL query to update only month in date?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:49:39

919 Views

To update only month in date, use MONTH(). Let us first create a table −mysql> create table DemoTable861(AdmissionDate date); Query OK, 0 rows affected (1.22 sec)Insert some records in the table using insert command −mysql> insert into DemoTable861 values('2019-01-21'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable861 ... Read More

How to order by the highest value from two columns in MySQL?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:48:44

568 Views

Let us first create a table −mysql> create table DemoTable834(    Value1 int,    Value2 int ); Query OK, 0 rows affected (1.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable834 values(10, 20); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable834 values(40, ... Read More

How to skip rows in MySQL?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:47:17

4K+ Views

To skip rows, use LIMIT OFFSET. Let us first create a table −mysql> create table DemoTable860(    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(100) ); Query OK, 0 rows affected (0.73 sec)Insert some records in the table using insert command −mysql> insert into DemoTable860(Name) values('Chris'); Query OK, ... Read More

How to subtract seconds from all the date records in a MySQL column?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:44:48

407 Views

Let us first create a table −mysql> create table DemoTable833(ArrivalTime datetime); Query OK, 0 rows affected (0.79 sec)Insert some records in the table using insert command −mysql> insert into DemoTable833 values('2019-01-10 12:40:50'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable833 values('2019-02-16 11:10:30'); Query OK, 1 row affected ... Read More

How to make numbers 'human readable' in MySQL?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:43:41

469 Views

To make numbers ‘human readable’ i.e. including separators, you need to use format(). Let us first create a table −mysql> create table DemoTable859(Number bigint); Query OK, 0 rows affected (1.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable859 values(747464646473737); Query OK, 1 row affected (0.45 ... Read More

Getting the first part from the Postcode in MySQL

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:41:17

221 Views

To get the first part, use SUBSTRING(). Let us first create a table −mysql> create table DemoTable858(PostCode varchar(100)); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable858 values('US90 456'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable858 ... Read More

Insert non-duplicates value in a MySQL table

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:40:19

210 Views

To allow inserting only non-duplicate values, use the UNIQUE constraint. Let us first create a table −mysql> create table DemoTable832(    FirstName varchar(100),    LastName varchar(100),    UNIQUE(FirstName, LastName) ); Query OK, 0 rows affected (0.87 sec)Insert some records in the table using insert command −mysql> insert into DemoTable832 values('John', ... Read More

Advertisements