- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
For this, you can use the property IS NULL for null values in MySQL. Let us first create a table −mysql> create table DemoTable ( Name varchar(100) ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(null); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(null); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 ... Read More
Let us first create a table −mysql> create table DemoTable ( Id int, ColorName varchar(100) ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100, 'Red'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(101, 'Green'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(101, 'Blue'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values(102, 'Yellow'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(100, 'Purple'); Query OK, 1 row affected (0.12 sec) mysql> insert ... Read More
Let us first create a table. Here, we have VARCHAR type for value −mysql> create table DemoTable ( Value varchar(100) ); Query OK, 0 rows affected (1.80 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('100'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('1244'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('15789'); Query OK, 1 row affected (0.18 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+-------+ | Value | +-------+ | 100 | ... Read More
% is a string formatting operator or interpolation operator. Given format % values (where format is a string), % conversion specifications in format are replaced with zero or more elements of values. The effect is similar to using the sprintf() in the C language. For example, >>> lang = "Python" >>> print "%s is awesome!" % lang Python is awesomeYou can also format numbers with this notation. For example, >>> cost = 128.527 >>> print "The book costs $%.2f at the bookstore" % cost The book costs $128.53 at the bookstoreYou can also use dictionaries to interpolate strings. They have ... Read More
Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, AddDay int, PostDate date ); Query OK, 0 rows affected (2.73 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(AddDay, PostDate) values(20, '2019-08-04'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(AddDay, PostDate) values(7, '2019-08-20'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(AddDay, PostDate) values(45, '2019-07-01'); Query OK, 1 row affected (0.19 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output ... Read More
Add a new column to table and fill it with the data of two other columns of the same table in MySQL?
Let us first create a table −mysql> create table DemoTable ( Price int, Quantity int ); Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(45, 3); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(90, 2); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(440, 1); Query OK, 1 row affected (0.09 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+-------+----------+ | Price | Quantity | +-------+----------+ | ... Read More
Let us first create a table −mysql> create table DemoTable1 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(100) ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1(Name) values('Chris'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1(Name) values('Robert'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1(Name) values('Mike'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1(Name) values('Sam'); Query OK, 1 row affected (0.07 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;This will produce ... Read More
Let us first create a table −mysql> create table DemoTable ( AdmissionDate date ); Query OK, 0 rows affected (0.87 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-08-24'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('2019-08-25'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('2019-08-20'); Query OK, 1 row affected (0.24 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+---------------+ | AdmissionDate | +---------------+ | 2019-08-24 | | 2019-08-25 | ... Read More
Following is the syntax −select *from yourTableName order by yourColumnName*1, yourColumnName;Let us first create a table −mysql> create table DemoTable ( Value varchar(100) ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('90'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('86'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('45'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('85'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('085'); Query OK, 1 row affected (0.14 sec) ... Read More
Following is the syntax −select if(yourColumnName, 1, -1) from yourTableName;Let us first create a table −mysql> create table DemoTable ( isMarried boolean ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(true); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(false); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(false); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(true); Query OK, 1 row affected (0.36 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will ... Read More
To Continue Learning Please Login
Login with Google