
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4381 Articles for MySQL

3K+ Views
To set values on the basis of conditions, use IF() method. Let us first create a table −mysql> create table DemoTable -> ( -> Age int -> ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(19); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(16); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(17); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(22); Query OK, 1 row affected (0.19 sec)Display all records from ... Read More

5K+ Views
Use concat() for this. Let us first create a table −mysql> create table DemoTable -> ( -> FirstName varchar(30), -> LastName varchar(30) -> ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 'Brown'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Adam', 'Smith'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('Carol', 'Taylor'); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following ... Read More

399 Views
Let’s say you need to get the difference between dates (JoiningDate – EndDate) of a month i.e. days to calculate the salary. The daily-wage salary is let’s say 300; therefore for 20 days, it will 6000. In the same way, for 27 days, it will be 8100.For our example, let us first create a tablemysql> create table DemoTable -> ( -> JoinDate date, -> EndDate date -> , -> Value int -> ); Query OK, 0 rows affected (1.16 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-01', '2019-01-31', ... Read More

236 Views
There is no default ORDER BY value in MySQL. You need to specify ORDER BY clause explicitly. Following is the syntax −ORDER BY ASC; OR ORDER BY DESC;Let us first create a table −mysql> create table DemoTable -> ( -> StudentName varchar(100) -> ); Query OK, 0 rows affected (0.82 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.15 sec) ... Read More

669 Views
To update the constraint, use the MODIFY command. Following is the syntax −alter table yourTableName modify yourExistingColumnName yourExistingDataType NOT NULL; Let us first create a table −mysql> create table DemoTable -> ( -> UserId int NOT NULL AUTO_INCREMENT, -> UserFirstName varchar(100), -> UserLastName varchar(100), -> UserEmailId varchar(100), -> UserPassword varchar(100), -> PRIMARY KEY(UserId) -> ); Query OK, 0 rows affected (0.91 sec)Following is the query to change the constraint of a column to NOT NULL −mysql> alter table DemoTable modify UserFirstName varchar(100) NOT NULL; Query OK, 0 rows affected (2.13 sec) Records: ... Read More

773 Views
Let us first create a table with one of the columns as DueDate and another one “RepeatTime, which displays how many times, let’s say a user was reminded to submit the payment −mysql> create table DemoTable -> ( -> DueDate date, -> RepeatTime int -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-23', 3); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-06-22', 6); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2019-03-28', 2); Query ... Read More

257 Views
Let us first create a table −mysql> create table DemoTable -> ( -> FirstName varchar(100), -> LastName varchar(100) -> ); Query OK, 0 rows affected (1.39 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Sam', 'Brown'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values(null, 'Smith'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('David', 'Taylor'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('Mike', null); Query OK, 1 row affected (0.45 sec)Display all records from the table using select statement −mysql> select ... Read More

554 Views
Let us first create a table −mysql> create table DemoTable -> ( -> Name varchar(100) -> ); Query OK, 0 rows affected (2.23 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Sam\''s'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable values('David\''s'); Query OK, 1 row affected (0.36 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+----------+ | Name | +----------+ | John ... Read More

779 Views
Use SUBSTRING_INDEX() for this. Let us first create a table −mysql> create table DemoTable -> ( -> UserMailId varchar(100) -> ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('John@gmail.com'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Carol94844@yahoo.com'); Query OK, 1 row affected (0.25 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+----------------------+ | UserMailId | +----------------------+ | John@gmail.com ... Read More

423 Views
For this, use where clause. Let us first create a table −mysql> create table DemoTable -> ( -> Number1 int, -> Number2 int -> ); Query OK, 0 rows affected (3.73 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(40, 50); Query OK, 1 row affected (0.60 sec) mysql> insert into DemoTable values(100, 59); Query OK, 1 row affected (0.56 sec) mysql> insert into DemoTable values(400, 500); Query OK, 1 row affected (0.40 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+---------+---------+ | ... Read More