Professional Documents
Culture Documents
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> insert into department(dno,dname,location)
-> values(10,'Accounting','New York'),
-> (20,'Research','Dallas'),
-> (30,'Sales','Chicago'),
-> (40,'Operation','Boston'),
-> (50,'Marketing','New Delhi');
Query OK, 5 rows affected (0.14 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql>
mysql> select distinct(job_type) from employee;
+-----------+
| job_type |
+-----------+
| clerk |
| sales_man |
| manager |
| President |
| Analyst |
+-----------+
5 rows in set (0.07 sec)
mysql>
mysql> select concat(ename,',',job_type) as 'name and job' from employee;
+------------------+
| name and job |
+------------------+
| Smith,clerk |
| Allan,sales_man |
| Ward,sales_man |
| Jones,manager |
| Martin,sales_man |
| Blake,Manager |
| Clark,Manager |
| King,President |
| Turner,sales_man |
| Adams,Clerk |
| Scott,Analyst |
| James,Clerk |
| Ford,analyst |
| Miller,clerk |
+------------------+
14 rows in set (0.08 sec)
mysql> select
concat(eno,',',ename,',',job_type,',',manager,',',hire_date,',',dno,',',commission,
',',salary) as THE_OUTPUT from employee;
+------------------------------------------------------+
| THE_OUTPUT |
+------------------------------------------------------+
| 736,Smith,clerk,790,1980-12-17,20,0.00,1000.00 |
| 749,Allan,sales_man,769,1981-02-20,30,300.00,2000.00 |
| 752,Ward,sales_man,769,1981-02-22,30,500.00,1300.00 |
| 756,Jones,manager,783,1981-04-02,20,0.00,2300.00 |
| NULL |
| 769,Blake,Manager,783,1981-05-01,30,0.00,2870.00 |
| 778,Clark,Manager,783,1981-06-09,10,0.00,2900.00 |
| NULL |
| 784,Turner,sales_man,769,1981-09-08,30,0.00,1450.00 |
| 787,Adams,Clerk,778,1983-01-12,20,0.00,1150.00 |
| 788,Scott,Analyst,756,1982-12-09,20,0.00,2850.00 |
| 790,James,Clerk,769,1981-12-03,30,0.00,950.00 |
| 792,Ford,analyst,756,1981-12-03,20,0.00,2600.00 |
| 793,Miller,clerk,788,1982-01-23,40,0.00,1300.00 |
+------------------------------------------------------+
14 rows in set (0.02 sec)
mysql> select ename,dno from employee where dno=10 ||dno=30 order by ename;
+--------+------+
| ename | dno |
+--------+------+
| Allan | 30 |
| Blake | 30 |
| Clark | 10 |
| James | 30 |
| King | 10 |
| Martin | 30 |
| Turner | 30 |
| Ward | 30 |
+--------+------+
8 rows in set (0.00 sec)
mysql> select ename,salary from employee where dno=10 ||dno=30 && salary >1500;
+-------+---------+
| ename | salary |
+-------+---------+
| Allan | 2000.00 |
| Blake | 2870.00 |
| Clark | 2900.00 |
| King | 2950.00 |
+-------+---------+
4 rows in set (0.00 sec)
mysql> select ename from employee where (ename like'%r%r%' ||ename like'%a%a%') &&
(dno=30 ||eno=778);
+--------+
| ename |
+--------+
| Allan |
| Turner |
+--------+
2 rows in set (0.00 sec)
mysql> select ename from employee where (ename like'%r%r%' ||ename like'%a%a%') &&
(dno=30 ||eno=778);
+--------+
| ename |
+--------+
| Allan |
| Turner |
+--------+
2 rows in set (0.00 sec)
mysql> commit;
Query OK, 0 rows affected (0.08 sec)
mysql>
mysql> insert into artists(artist_id,sname,location)
-> values(1001,'Alla Rakha Rehman','Chennai'),
-> (1002,'Kailas Kher','Delhi'),
-> (1003,'Rahul Dev Barman','Kolkata'),
-> (1004,'Lucky Ali','Mumbai');
Query OK, 4 rows affected (0.14 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql>
mysql>
mysql> create table dept(
-> did int primary key,
-> dname varchar(255),
-> budget int,
-> managerid int
-> );
Query OK, 0 rows affected (0.52 sec)
mysql>
mysql> insert into emp(eid,ename,age,salary)
-> values(1001,'Sabeer Bhatia',60,50000),
-> (1002,'Pranav Mistry',65,55000),
-> (1003,'Sam Pitroda',50,60000),
-> (1004,'Mark Zuckerberg',50,35000),
-> (1005,'Larry Page',40,45000),
-> (1006,'Steve Ballmer',45,46000),
-> (1007,'Tim Cook',80,65000);
Query OK, 7 rows affected (0.08 sec)
Records: 7 Duplicates: 0 Warnings: 0
mysql>
mysql> create table catalog(
-> sid int,
-> pid int,
-> price int,
-> foreign key(sid) references suppliers(sid),
-> foreign key(pid) references parts(pid)
-> );
Query OK, 0 rows affected (0.56 sec)
mysql>
mysql> select * from reserves;
+------+------+------+
| sid | bid | day |
+------+------+------+
| 1001 | 12 | 2 |
| 1001 | 13 | 2 |
| 1002 | 14 | 3 |
| 1002 | 15 | 4 |
| 1003 | 12 | 5 |
| 1004 | 12 | 6 |
| 1005 | 15 | 1 |
+------+------+------+
7 rows in set (0.00 sec)
mysql>
mysql> insert into professor(profid,deptid,profname,profage,salary)
-> values(2222,10,'Santosh Kumar',45,45000),
-> (2223,11,'Sukumar',44,55000),
-> (2224,11,'Naveen Garg',34,65000),
-> (2225,12,'Bimal Roy',49,47000),
-> (2226,13,'Sia Bal Pal',39,48000),
-> (2227,12,'Pramod Kumar Kapoor',40,79000),
-> (2228,13,'Sandeep Sen',42,59000);
Query OK, 7 rows affected (0.11 sec)
Records: 7 Duplicates: 0 Warnings: 0
mysql>
mysql>
mysql> create table pizza(
-> pid int primary key,
-> pname varchar(255),
-> size int
-> );
Query OK, 0 rows affected (0.61 sec)
mysql> select
-> * from store;
+-----------------+---------------+---------+
| sname | location | Quality |
+-----------------+---------------+---------+
| Cannaught Place | Central Delhi | A |
| India Gate | Central Delhi | B |
| North Store | Civil Lines | C |
| Saket | South Delhi | B |
| South Store | Malviya Nagar | D |
+-----------------+---------------+---------+
5 rows in set (0.00 sec)
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> select pname from pizza where pname like'__i%';
Empty set (0.00 sec)
mysql>
mysql> select * from pizza;
+-----+-----------+------+
| pid | pname | size |
+-----+-----------+------+
| 101 | Domino | 10 |
| 102 | Pizza Hut | 20 |
| 103 | PSD | 30 |
| 104 | Subway | 25 |
| 105 | Mc Donald | 30 |
| 106 | Nirullas | 28 |
+-----+-----------+------+
6 rows in set (0.00 sec)
mysql>
mysql> select pname from pizza where pid=(select pid from soldby group by pid order
by count(pid) desc limit 1);
+--------+
| pname |
+--------+
| Domino |
+--------+
1 row in set (0.06 sec)
mysql>
mysql> select pname from pizza where pid not in (select pid from soldby);
+----------+
| pname |
+----------+
| Nirullas |
+----------+
1 row in set (0.02 sec)
mysql> select pname from pizza where pid in(select pid from soldby where
sname='north store');
+-----------+
| pname |
+-----------+
| Domino |
| Mc Donald |
+-----------+
2 rows in set (0.06 sec)
mysql> select pname from where pid=( select max(soldby) from soldby);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'where
pid=( select max(soldby) from soldby)' at line 1
mysql> select pname from where pid=( select max(soldby) from soldby);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'where
pid=( select max(soldby) from soldby)' at line 1
mysql> select pname from where pid=( select max(price) from soldby);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'where
pid=( select max(price) from soldby)' at line 1
mysql> select pname from pizza where pid=( select max(price) from soldby);
Empty set (0.00 sec)
mysql> select pname from pizza where pid=(select pid from soldby group by pid order
by count(pid) desc limit 1);
+--------+
| pname |
+--------+
| Domino |
+--------+
1 row in set (0.00 sec)
mysql> select pname from pizza where pid is not in ( select pid from soldby);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'in
( select pid from soldby)' at line 1
mysql> select pname from pizza where pid not in ( select pid from soldby);
+----------+
| pname |
+----------+
| Nirullas |
+----------+
1 row in set (0.00 sec)
mysql> select pname from pizza where pid in ( select pid from soldby where
sname='north store');
+-----------+
| pname |
+-----------+
| Domino |
| Mc Donald |
+-----------+
2 rows in set (0.00 sec)
mysql> select ename from employee where salary >(select max(salary) from employee
where ename='clerk');
Empty set (0.00 sec)
mysql> select ename from employee where salary >(select max(salary) from employee
where job-type='clerk');
ERROR 1054 (42S22): Unknown column 'job' in 'where clause'
mysql> select ename from employee where salary >(select max(salary) from employee
where job_type='clerk');
+--------+
| ename |
+--------+
| Allan |
| Jones |
| Blake |
| Clark |
| King |
| Turner |
| Scott |
| Ford |
+--------+
8 rows in set (0.00 sec)
mysql>