In [2]:
show databases
Database
company
information_schema
raj
In [3]:
use company
yes
In [4]:
CREATE TABLE CUSTOMERS(
   ID   INT              NOT NULL,
   NAME VARCHAR (20)     NOT NULL,
   AGE  INT              NOT NULL,
   ADDRESS  CHAR (25) ,
   SALARY   DECIMAL (18, 2),       
   PRIMARY KEY (ID)
);
yes
In [5]:
show tables
Tables_in_company
CUSTOMERS
In [6]:
describe customers
Field Type Null Key Default Extra
ID int NO PRI None
NAME varchar(20) NO None
AGE int NO None
ADDRESS char(25) YES None
SALARY decimal(18,2) YES None
In [7]:
INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (1, 'Ramesh', 32, 'Ahmedabad',2000.0);
yes
In [8]:
INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (2, 'Khilan', 25, 'Delhi', 1500.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (3, 'kaushik', 23, 'Kota', 2000.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (4, 'Chaitali', 25, 'Mumbai', 6500.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (5, 'Hardik', 27, 'Bhopal', 8500.00 );

INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)
VALUES (6, 'Komal', 22, 'MP', 4500.00 );

INSERT INTO CUSTOMERS 
VALUES (7, 'Muffy', 24, 'Indore', 10000.00 );
yes
In [12]:
SELECT ID,NAME,AGE,ADDRESS,SALARY FROM CUSTOMERS
ID NAME AGE ADDRESS SALARY
1 Ramesh 32 Ahmedabad 2000.00
2 Khilan 25 Delhi 1500.00
3 kaushik 23 Kota 2000.00
4 Chaitali 25 Mumbai 6500.00
5 Hardik 27 Bhopal 8500.00
6 Komal 22 MP 4500.00
7 Muffy 24 Indore 10000.00
In [13]:
select * from customers
ID NAME AGE ADDRESS SALARY
1 Ramesh 32 Ahmedabad 2000.00
2 Khilan 25 Delhi 1500.00
3 kaushik 23 Kota 2000.00
4 Chaitali 25 Mumbai 6500.00
5 Hardik 27 Bhopal 8500.00
6 Komal 22 MP 4500.00
7 Muffy 24 Indore 10000.00
In [14]:
select ID,NAME,SALARY from customers
ID NAME SALARY
1 Ramesh 2000.00
2 Khilan 1500.00
3 kaushik 2000.00
4 Chaitali 6500.00
5 Hardik 8500.00
6 Komal 4500.00
7 Muffy 10000.00
In [15]:
SELECT ID, NAME, SALARY 
FROM   CUSTOMERS
WHERE  SALARY > 2000;
ID NAME SALARY
4 Chaitali 6500.00
5 Hardik 8500.00
6 Komal 4500.00
7 Muffy 10000.00
In [16]:
SELECT ID, NAME, SALARY 
FROM   CUSTOMERS
WHERE  SALARY > 2000 and SALARY < 10000;
ID NAME SALARY
4 Chaitali 6500.00
5 Hardik 8500.00
6 Komal 4500.00
In [17]:
SELECT ID, NAME, SALARY 
FROM CUSTOMERS
WHERE NAME = 'Hardik';
ID NAME SALARY
5 Hardik 8500.00
In [22]:
SELECT ID, NAME, SALARY, AGE 
FROM   CUSTOMERS
WHERE  SALARY > 2000 AND age < 25;
ID NAME SALARY AGE
6 Komal 4500.00 22
7 Muffy 10000.00 24
In [24]:
SELECT ID, NAME, SALARY, AGE 
FROM   CUSTOMERS
WHERE  SALARY > 2000 OR age < 25;
ID NAME SALARY AGE
3 kaushik 2000.00 23
4 Chaitali 6500.00 25
5 Hardik 8500.00 27
6 Komal 4500.00 22
7 Muffy 10000.00 24
In [25]:
SELECT * FROM CUSTOMERS
WHERE  NAME LIKE 'R%';
ID NAME AGE ADDRESS SALARY
1 Ramesh 32 Ahmedabad 2000.00
In [29]:
SELECT * FROM CUSTOMERS
WHERE  NAME LIKE '%i%';
ID NAME AGE ADDRESS SALARY
2 Khilan 25 Delhi 1500.00
3 kaushik 23 Kota 2000.00
4 Chaitali 25 Mumbai 6500.00
5 Hardik 27 Bhopal 8500.00
In [30]:
select upper(name), age+10 from customers
upper(name) age+10
RAMESH 42
KHILAN 35
KAUSHIK 33
CHAITALI 35
HARDIK 37
KOMAL 32
MUFFY 34
In [32]:
SELECT * 
FROM   CUSTOMERS
WHERE  NAME LIKE '__a%';
ID NAME AGE ADDRESS SALARY
4 Chaitali 25 Mumbai 6500.00
In [36]:
SELECT * 
FROM   CUSTOMERS
order by name asc;
ID NAME AGE ADDRESS SALARY
4 Chaitali 25 Mumbai 6500.00
5 Hardik 27 Bhopal 8500.00
3 kaushik 23 Kota 2000.00
2 Khilan 25 Delhi 1500.00
6 Komal 22 MP 4500.00
7 Muffy 24 Indore 10000.00
1 Ramesh 32 Ahmedabad 2000.00
In [ ]: