mysql> use raj
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> (select distinct id, name from CUSTOMERS where age > 30);
+----+--------+
| id | name   |
+----+--------+
|  1 | Ramesh |
|  8 | Raj    |
+----+--------+
2 rows in set (0.00 sec)

mysql> (select distinct id, name
    -> from CUSTOMERS
    -> where salary > 8000);
+----+--------+
| id | name   |
+----+--------+
|  5 | Hardik |
|  7 | Muffy  |
|  8 | Raj    |
+----+--------+
3 rows in set (0.01 sec)

mysql> (select distinct id, name from CUSTOMERS where age > 30) union 
    -> (select distinct id, name
    -> from CUSTOMERS
    -> where salary > 8000);
+----+--------+
| id | name   |
+----+--------+
|  1 | Ramesh |
|  8 | Raj    |
|  5 | Hardik |
|  7 | Muffy  |
+----+--------+
4 rows in set (0.01 sec)

mysql> (select distinct id, name from CUSTOMERS where age > 30) union all (select distinct id, name from CUSTOMERS where salary > 8000);
+----+--------+
| id | name   |
+----+--------+
|  1 | Ramesh |
|  8 | Raj    |
|  5 | Hardik |
|  7 | Muffy  |
|  8 | Raj    |
+----+--------+
5 rows in set (0.00 sec)

mysql> select distinct id, name from CUSTOMERS where age > 30 or salary > 8000;
+----+--------+
| id | name   |
+----+--------+
|  1 | Ramesh |
|  5 | Hardik |
|  7 | Muffy  |
|  8 | Raj    |
+----+--------+
4 rows in set (0.00 sec)

mysql> select count(oid)
    -> from   CUSTOMERS, ORDERS
    -> where  id = customer_id
    -> group by id;
+------------+
| count(oid) |
+------------+
|          2 |
|          7 |
|          4 |
|          6 |
|          1 |
+------------+
5 rows in set (0.00 sec)

mysql> select id,count(oid)
    -> from   CUSTOMERS, ORDERS
    -> where  id = customer_id
    -> group by id
    -> ;
+----+------------+
| id | count(oid) |
+----+------------+
|  2 |          2 |
|  3 |          7 |
|  4 |          4 |
|  5 |          6 |
|  6 |          1 |
+----+------------+
5 rows in set (0.00 sec)

mysql> select id,name,count(oid)
    -> from   CUSTOMERS, ORDERS
    -> where  id = customer_id
    -> group by id;
+----+----------+------------+
| id | name     | count(oid) |
+----+----------+------------+
|  2 | Khilan   |          2 |
|  3 | kaushik  |          7 |
|  4 | Chaitali |          4 |
|  5 | Hardik   |          6 |
|  6 | Komal    |          1 |
+----+----------+------------+
5 rows in set (0.00 sec)

mysql> select id,name,count(oid),sum(amount)
    -> from   CUSTOMERS, ORDERS
    -> where  id = customer_id
    -> group by id;
+----+----------+------------+-------------+
| id | name     | count(oid) | sum(amount) |
+----+----------+------------+-------------+
|  3 | kaushik  |          7 |       16960 |
|  2 | Khilan   |          2 |        2120 |
|  4 | Chaitali |          4 |       10120 |
|  6 | Komal    |          1 |        6560 |
|  5 | Hardik   |          6 |       16760 |
+----+----------+------------+-------------+
5 rows in set (0.00 sec)

mysql> select id,name,count(oid) NUM_ORDERS,sum(amount) TOTAL_AMOUNT
    -> from   CUSTOMERS, ORDERS
    -> where  id = customer_id
    -> group by id;
+----+----------+------------+--------------+
| id | name     | NUM_ORDERS | TOTAL_AMOUNT |
+----+----------+------------+--------------+
|  3 | kaushik  |          7 |        16960 |
|  2 | Khilan   |          2 |         2120 |
|  4 | Chaitali |          4 |        10120 |
|  6 | Komal    |          1 |         6560 |
|  5 | Hardik   |          6 |        16760 |
+----+----------+------------+--------------+
5 rows in set (0.01 sec)

mysql> exit;