AmitDiwan has Published 10740 Articles

What does parenthesis mean in MySQL SELECT (COLNAME)?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 13:02:08

476 Views

The SELECT(COLNAME) means, we are creating an alias for that column. Let us see an example and create a table −mysql> create table DemoTable865(    FirstName varchar(100),    LastName varchar(100) ); Query OK, 0 rows affected (0.77 sec)Insert some records in the table using insert command −mysql> insert into DemoTable865 ... Read More

Return only the non-empty and non-null values from a table and fill the empty and NULL values with the corresponding column values in MySQL?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 13:01:17

248 Views

Let us first create a table −mysql> create table DemoTable839(    StudentFirstName varchar(100),    StudentLastName varchar(100) ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable839 values('Chris', 'Brown'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable839 values('', ... Read More

How can I create a MySQL table with a column with only 3 possible given values?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:59:00

291 Views

For this, use the ENUM data type. Let us first create a table −mysql> create table DemoTable838(Color ENUM('RED', 'GREEN', 'BLUE')); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable838 values('RED'); Query OK, 1 row affected (0.11 sec) mysql> insert into ... Read More

How to compare Year, Month and Day in a MySQL query and display matching records

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:58:07

528 Views

For this, you can use DATE(). Let us first create a table −mysql> create table DemoTable864(DueDateTime timestamp); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable864 values('2019-01-10 12 −34 −55'); Query OK, 1 row affected (0.26 sec) mysql> insert into ... Read More

Replace the empty values from a MySQL table with a specific value

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:57:02

467 Views

Let us first create a table −mysql> create table DemoTable837(Name varchar(100)); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable837 values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable837 values(''); Query OK, 1 row affected (0.23 sec) ... Read More

MySQL query to get the dates between range of records displaying student’s Date of Birth?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 12:55:31

408 Views

For fetching records between dates, use BETWEEN. Let us first create a table −mysql> create table DemoTable863(StudentDateOfBirth date); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable863 values('1998-01-10'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable863 values('2000-10-15'); ... Read More

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

706 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

972 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

Advertisements