0% found this document useful (0 votes)
26 views10 pages

Rahul SQL File 18.04.2024

Uploaded by

Ronny Sakhare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views10 pages

Rahul SQL File 18.04.2024

Uploaded by

Ronny Sakhare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 10

Microsoft Windows [Version 10.0.19045.

4291]
(c) Microsoft Corporation. All rights reserved.

C:\Users\Admin>mysql -u root -p
Enter password: *********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 20
Server version: 8.0.32 MySQL Community Server - GPL

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its


affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;


+--------------------+
| Database |
+--------------------+
| books |
| classwork_db |
| collage |
| customer |
| ecdac |
| emp |
| information_schema |
| mysql |
| northwind_db |
| performance_schema |
| sales_db |
| sqll |
| sys |
+--------------------+
13 rows in set (0.00 sec)

mysql> use classwork


ERROR 1049 (42000): Unknown database 'classwork'
mysql> use classwork_db;
Database changed
mysql> show tables;
+------------------------+
| Tables_in_classwork_db |
+------------------------+
| bonus |
| books |
| dept |
| dummy |
| emp |
| salgrade |
+------------------------+
6 rows in set (0.00 sec)

mysql> describe emp;


+--------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+--------------+------+-----+---------+-------+
| empno | int | NO | PRI | NULL | |
| ename | varchar(40) | YES | | NULL | |
| job | varchar(40) | YES | | NULL | |
| mgr | int | YES | | NULL | |
| hire | date | YES | | NULL | |
| sal | decimal(8,2) | YES | | NULL | |
| comm | decimal(8,2) | YES | | NULL | |
| deptno | int | YES | MUL | NULL | |
+--------+--------------+------+-----+---------+-------+
8 rows in set (0.03 sec)

mysql> select * FROM EMP;


+-------+--------+-----------+------+------------+---------+---------+--------+
| empno | ename | job | mgr | hire | sal | comm | deptno |
+-------+--------+-----------+------+------------+---------+---------+--------+
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 | 3000.00 | NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1983-01-12 | 1100.00 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 |
+-------+--------+-----------+------+------------+---------+---------+--------+
14 rows in set (0.00 sec)

mysql> SELECT COUNT(*),job from emp where job = "manager";


+----------+---------+
| COUNT(*) | job |
+----------+---------+
| 3 | MANAGER |
+----------+---------+
1 row in set (0.00 sec)

mysql> SELECT COUNT(*),job from emp group by job;


+----------+-----------+
| COUNT(*) | job |
+----------+-----------+
| 4 | CLERK |
| 4 | SALESMAN |
| 3 | MANAGER |
| 2 | ANALYST |
| 1 | PRESIDENT |
+----------+-----------+
5 rows in set (0.00 sec)

mysql> SELECT COUNT(job) from emp;


+------------+
| COUNT(job) |
+------------+
| 14 |
+------------+
1 row in set (0.00 sec)
mysql> SELECT COUNT(*),job from emp group by job;
+----------+-----------+
| COUNT(*) | job |
+----------+-----------+
| 4 | CLERK |
| 4 | SALESMAN |
| 3 | MANAGER |
| 2 | ANALYST |
| 1 | PRESIDENT |
+----------+-----------+
5 rows in set (0.00 sec)

mysql> select * FROM EMP;


+-------+--------+-----------+------+------------+---------+---------+--------+
| empno | ename | job | mgr | hire | sal | comm | deptno |
+-------+--------+-----------+------+------------+---------+---------+--------+
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 | 3000.00 | NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1983-01-12 | 1100.00 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 |
+-------+--------+-----------+------+------------+---------+---------+--------+
14 rows in set (0.00 sec)

mysql> select sal from emp where sal 800 and 5000;
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 '800 and
5000' at line 1
mysql> select sal from emp where sal between 800 and 5000;
+---------+
| sal |
+---------+
| 800.00 |
| 1600.00 |
| 1250.00 |
| 2975.00 |
| 1250.00 |
| 2850.00 |
| 2450.00 |
| 3000.00 |
| 5000.00 |
| 1500.00 |
| 1100.00 |
| 950.00 |
| 3000.00 |
| 1300.00 |
+---------+
14 rows in set (0.00 sec)

mysql> select sal from emp where sal between 800 and 2000;
+---------+
| sal |
+---------+
| 800.00 |
| 1600.00 |
| 1250.00 |
| 1250.00 |
| 1500.00 |
| 1100.00 |
| 950.00 |
| 1300.00 |
+---------+
8 rows in set (0.00 sec)

mysql> select sal from emp order by desc;


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 'desc' at
line 1
mysql> select sal from emp where order by desc;
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 'order by
desc' at line 1
mysql> select * from emp order by sal desc;
+-------+--------+-----------+------+------------+---------+---------+--------+
| empno | ename | job | mgr | hire | sal | comm | deptno |
+-------+--------+-----------+------+------------+---------+---------+--------+
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 | 3000.00 | NULL | 20 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1983-01-12 | 1100.00 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 |
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 |
+-------+--------+-----------+------+------------+---------+---------+--------+
14 rows in set (0.00 sec)

mysql> select sal from emp where sal between 800 and 2000 order by sal desc;
+---------+
| sal |
+---------+
| 1600.00 |
| 1500.00 |
| 1300.00 |
| 1250.00 |
| 1250.00 |
| 1100.00 |
| 950.00 |
| 800.00 |
+---------+
8 rows in set (0.00 sec)

mysql> select sal from emp where sal between 800 and 2000 order by sal limit 1,1;
+--------+
| sal |
+--------+
| 950.00 |
+--------+
1 row in set (0.00 sec)

mysql> select sal from emp where sal between 800 and 2000 order by sal desc limit
1,1;
+---------+
| sal |
+---------+
| 1500.00 |
+---------+
1 row in set (0.00 sec)

mysql> select sal from emp where sal 800 and 3000;
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 '800 and
3000' at line 1
mysql> select sal from emp where sal between 800 and 3000 order by sal desc;
+---------+
| sal |
+---------+
| 3000.00 |
| 3000.00 |
| 2975.00 |
| 2850.00 |
| 2450.00 |
| 1600.00 |
| 1500.00 |
| 1300.00 |
| 1250.00 |
| 1250.00 |
| 1100.00 |
| 950.00 |
| 800.00 |
+---------+
13 rows in set (0.00 sec)

mysql> select distinct(sal) from emp where sal between 800 and 3000 order by sal
desc;
+---------+
| sal |
+---------+
| 3000.00 |
| 2975.00 |
| 2850.00 |
| 2450.00 |
| 1600.00 |
| 1500.00 |
| 1300.00 |
| 1250.00 |
| 1100.00 |
| 950.00 |
| 800.00 |
+---------+
11 rows in set (0.00 sec)
mysql> select * from Emp where sal 800 and 1500 group by sal;
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 '800 and
1500 group by sal' at line 1
mysql> select * from Emp where group by sal;
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 'group by
sal' at line 1
mysql> select sal from Emp group by sal;
+---------+
| sal |
+---------+
| 800.00 |
| 1600.00 |
| 1250.00 |
| 2975.00 |
| 2850.00 |
| 2450.00 |
| 3000.00 |
| 5000.00 |
| 1500.00 |
| 1100.00 |
| 950.00 |
| 1300.00 |
+---------+
12 rows in set (0.00 sec)

mysql> select sal from emp where sal 800 and 1600 group by sal;
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 '800 and
1600 group by sal' at line 1
mysql> select sal from Emp where sal between 800 and 1000 group by sal;
+--------+
| sal |
+--------+
| 800.00 |
| 950.00 |
+--------+
2 rows in set (0.00 sec)

mysql> select sal from emp where sal between 800 and 1000 order by sal desc;
+--------+
| sal |
+--------+
| 950.00 |
| 800.00 |
+--------+
2 rows in set (0.00 sec)

mysql> select sal from emp where sal between 800 and 2000 order by sal desc;
+---------+
| sal |
+---------+
| 1600.00 |
| 1500.00 |
| 1300.00 |
| 1250.00 |
| 1250.00 |
| 1100.00 |
| 950.00 |
| 800.00 |
+---------+
8 rows in set (0.00 sec)

mysql> select sal,empno from emp where sal between 800 and 2000 order by sal desc;
+---------+-------+
| sal | empno |
+---------+-------+
| 1600.00 | 7499 |
| 1500.00 | 7844 |
| 1300.00 | 7934 |
| 1250.00 | 7521 |
| 1250.00 | 7654 |
| 1100.00 | 7876 |
| 950.00 | 7900 |
| 800.00 | 7369 |
+---------+-------+
8 rows in set (0.00 sec)

mysql> select sal,empno,ename from emp where sal between 800 and 2000 order by sal
desc;
+---------+-------+--------+
| sal | empno | ename |
+---------+-------+--------+
| 1600.00 | 7499 | ALLEN |
| 1500.00 | 7844 | TURNER |
| 1300.00 | 7934 | MILLER |
| 1250.00 | 7521 | WARD |
| 1250.00 | 7654 | MARTIN |
| 1100.00 | 7876 | ADAMS |
| 950.00 | 7900 | JAMES |
| 800.00 | 7369 | SMITH |
+---------+-------+--------+
8 rows in set (0.00 sec)

mysql> select * from emp;


+-------+--------+-----------+------+------------+---------+---------+--------+
| empno | ename | job | mgr | hire | sal | comm | deptno |
+-------+--------+-----------+------+------------+---------+---------+--------+
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 | 3000.00 | NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1983-01-12 | 1100.00 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 |
+-------+--------+-----------+------+------------+---------+---------+--------+
14 rows in set (0.00 sec)

mysql> select count(), sal ,job from emp where sal between 800 and 3000 group by
sal;
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 '),
sal ,job from emp where sal between 800 and 3000 group by sal' at line 1
mysql> select count(),sal,job from emp where sal between 800 and 3000 group by sal;
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
'),sal,job from emp where sal between 800 and 3000 group by sal' at line 1
mysql> select count(),sal,job from emp where sal between 800 and 3000 group by sal,
job having count()>1;
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
'),sal,job from emp where sal between 800 and 3000 group by sal, job having count'
at line 1
mysql> use classwork_db;
Database changed
mysql> select count(),sal,job from emp where sal between 800 and 3000 group by sal,
job having count()>1;
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
'),sal,job from emp where sal between 800 and 3000 group by sal, job having count'
at line 1
mysql> select count(*),sal,job from emp where sal between 800 and 3000 group by
sal, job having count()>1;
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 ')>1' at
line 1
mysql> select count(),sal,job from emp where sal between 800 and 3000 group by sal,
job having count()>1;
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
'),sal,job from emp where sal between 800 and 3000 group by sal, job having count'
at line 1
mysql> select count(),sal,job from emp where sal between 800 and 3000 groupby
sal,job having count();
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
'),sal,job from emp where sal between 800 and 3000 groupby sal,job having count()'
at line 1
mysql> select count(),sal,job from emp where sal between 800 and 3000 groupby
sal,job havingcount();
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
'),sal,job from emp where sal between 800 and 3000 groupby sal,job havingcount()'
at line 1
mysql> select count(),sal,job from emp where sal between 800 and 3000 groupby
sal,job having count()>1;
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
'),sal,job from emp where sal between 800 and 3000 groupby sal,job having count()'
at line 1
mysql> select count(),sal,job from emp where sal between 800 and 3000 groupby
sal,job havingcount()>1;
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
'),sal,job from emp where sal between 800 and 3000 groupby sal,job havingcount()>'
at line 1
mysql> select count(),sal,job from emp where sal between 800 and 3000 group by
sal,job having count()>1;
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
'),sal,job from emp where sal between 800 and 3000 group by sal,job having count('
at line 1
mysql> select count()sal,job from emp where sal between 800 and 3000 group by
sal,job having count()>1;
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 ')sal,job
from emp where sal between 800 and 3000 group by sal,job having count()' at line 1
mysql> select * from emp ;
+-------+--------+-----------+------+------------+---------+---------+--------+
| empno | ename | job | mgr | hire | sal | comm | deptno |
+-------+--------+-----------+------+------------+---------+---------+--------+
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 | 800.00 | NULL | 20 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 | 1600.00 | 300.00 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 | 1250.00 | 500.00 | 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 | 2975.00 | NULL | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 | 1250.00 | 1400.00 | 30 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 | 2850.00 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 | 2450.00 | NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1982-12-09 | 3000.00 | NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 | 5000.00 | NULL | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 | 1500.00 | 0.00 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1983-01-12 | 1100.00 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 | 950.00 | NULL | 30 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 | 3000.00 | NULL | 20 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 | 1300.00 | NULL | 10 |
+-------+--------+-----------+------+------------+---------+---------+--------+
14 rows in set (0.00 sec)

mysql> select count(sal),job,mgr from emp;


ERROR 1140 (42000): In aggregated query without GROUP BY, expression #2 of SELECT
list contains nonaggregated column 'classwork_db.emp.job'; this is incompatible
with sql_mode=only_full_group_by
mysql> select count(sal) from emp;
+------------+
| count(sal) |
+------------+
| 14 |
+------------+
1 row in set (0.00 sec)

mysql> select count(*),job,sal, from emp;


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 'from
emp' at line 1
mysql> select count(*),job,sal from emp;
ERROR 1140 (42000): In aggregated query without GROUP BY, expression #2 of SELECT
list contains nonaggregated column 'classwork_db.emp.job'; this is incompatible
with sql_mode=only_full_group_by
mysql> select count(*),job,sal from emp group by job;
ERROR 1055 (42000): Expression #3 of SELECT list is not in GROUP BY clause and
contains nonaggregated column 'classwork_db.emp.sal' which is not functionally
dependent on columns in GROUP BY clause; this is incompatible with
sql_mode=only_full_group_by
mysql> select count(job),sal from emp group by job;
ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and
contains nonaggregated column 'classwork_db.emp.sal' which is not functionally
dependent on columns in GROUP BY clause; this is incompatible with
sql_mode=only_full_group_by
mysql> select count(job) from emp group by job;
+------------+
| count(job) |
+------------+
| 4 |
| 4 |
| 3 |
| 2 |
| 1 |
+------------+
5 rows in set (0.00 sec)

mysql> select job,ename from emp group by job;


ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and
contains nonaggregated column 'classwork_db.emp.ename' which is not functionally
dependent on columns in GROUP BY clause; this is incompatible with
sql_mode=only_full_group_by
mysql> select job from emp group by job;
+-----------+
| job |
+-----------+
| CLERK |
| SALESMAN |
| MANAGER |
| ANALYST |
| PRESIDENT |
+-----------+
5 rows in set (0.00 sec)

mysql> select count(job), job from emp group by job;


+------------+-----------+
| count(job) | job |
+------------+-----------+
| 4 | CLERK |
| 4 | SALESMAN |
| 3 | MANAGER |
| 2 | ANALYST |
| 1 | PRESIDENT |
+------------+-----------+
5 rows in set (0.00 sec)

mysql> select count(), sal ,job from emp where sal between 800 and 3000 group by
sal, job having count()>1;
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 '),
sal ,job from emp where sal between 800 and 3000 group by sal, job having cou' at
line 1
mysql> select count(sal), sal ,job from emp where sal between 800 and 3000 group by
sal;
ERROR 1055 (42000): Expression #3 of SELECT list is not in GROUP BY clause and
contains nonaggregated column 'classwork_db.emp.job' which is not functionally
dependent on columns in GROUP BY clause; this is incompatible with
sql_mode=only_full_group_by
mysql> select count(sal),job from emp where sal between 800 and 3000 group by sal;
ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and
contains nonaggregated column 'classwork_db.emp.job' which is not functionally
dependent on columns in GROUP BY clause; this is incompatible with
sql_mode=only_full_group_by
mysql> select count(sal),job from emp where sal between 800 and 3000 group by sal;

You might also like