SQL Practice
SQL Practice
SQL Practice
mysql> select
personal_demo.Stud_id,personal_demo.Sname,personal_demo.Gen
der,personal_demo.Address,personal_demo.Email,personal_demo.P
hone,student_demo.Stud_id,student_demo.Student_Name,student_
demo.Semester,student_demo.Subject_1,student_demo.Subject_2,s
tudent_demo.Subject_3,student_demo.Subject_4,student_demo.Su
bject_5
-> FROM personal_demo
-> JOIN student_demo ON
personal_demo.Stud_id=student_demo.Stud_id;
+---------+--------------------+--------+----------+-------------------------------+----
--------+---------+--------------------+----------+-----------+-----------+-----------
+-----------+-----------+
| Stud_id | Sname | Gender | Address | Email |
Phone | Stud_id | Student_Name | Semester | Subject_1 |
Subject_2 | Subject_3 | Subject_4 | Subject_5 |
+---------+--------------------+--------+----------+-------------------------------+----
--------+---------+--------------------+----------+-----------+-----------+-----------
+-----------+-----------+
| S001 | Demanshu Chaudhari | Male | Dombivli |
demanshuchaudhari27@gmail.com | 7715907377 | S001 |
Demanshu Chaudhari | 1| 69 | 55 | 59 | 75 |
91 |
| S001 | Demanshu Chaudhari | Male | Dombivli |
demanshuchaudhari27@gmail.com | 7715907377 | S001 |
Demanshu Chaudhari | 2| 57 | 91 | 53 | 59 |
73 |
| S001 | Demanshu Chaudhari | Male | Dombivli |
demanshuchaudhari27@gmail.com | 7715907377 | S001 |
Demanshu Chaudhari | 3| 66 | 57 | 85 | 95 |
92 |
| S001 | Demanshu Chaudhari | Male | Dombivli |
demanshuchaudhari27@gmail.com | 7715907377 | S001 |
Demanshu Chaudhari | 4| 64 | 65 | 72 | 61 |
54 |
| S002 | Pranav Kankekar | Male | Worli |
pranavkankekar04@gmail.com | 9892395141 | S002 | Pranav
Kankekar | 1| 71 | 78 | 55 | 93 | 54 |
| S002 | Pranav Kankekar | Male | Worli |
pranavkankekar04@gmail.com | 9892395141 | S002 | Pranav
Kankekar | 2| 68 | 51 | 93 | 82 | 94 |
| S002 | Pranav Kankekar | Male | Worli |
pranavkankekar04@gmail.com | 9892395141 | S002 | Pranav
Kankekar | 3| 66 | 96 | 54 | 55 | 63 |
| S002 | Pranav Kankekar | Male | Worli |
pranavkankekar04@gmail.com | 9892395141 | S002 | Pranav
Kankekar | 4| 68 | 53 | 84 | 81 | 85 |
| S003 | Neeraj Veldandi | Male | Kurla |
neerajveldandi08@gmail.com | 7021447090 | S003 | Neeraj
Veldandi | 1| 59 | 90 | 90 | 95 | 95 |
| S003 | Neeraj Veldandi | Male | Kurla |
neerajveldandi08@gmail.com | 7021447090 | S003 | Neeraj
Veldandi | 2| 54 | 62 | 89 | 55 | 61 |
| S003 | Neeraj Veldandi | Male | Kurla |
neerajveldandi08@gmail.com | 7021447090 | S003 | Neeraj
Veldandi | 3| 98 | 98 | 60 | 98 | 69 |
| S003 | Neeraj Veldandi | Male | Kurla |
neerajveldandi08@gmail.com | 7021447090 | S003 | Neeraj
Veldandi | 4| 93 | 74 | 70 | 97 | 62 |
| S004 | Aaryan Raut | Male | Dadar |
aaryanraut09@gmail.com | 8369156737 | S004 | Aaryan Raut
| 1| 50 | 51 | 84 | 65 | 89 |
| S004 | Aaryan Raut | Male | Dadar |
aaryanraut09@gmail.com | 8369156737 | S004 | Aaryan Raut
| 2| 71 | 53 | 58 | 95 | 72 |
| S004 | Aaryan Raut | Male | Dadar |
aaryanraut09@gmail.com | 8369156737 | S004 | Aaryan Raut
| 3| 75 | 89 | 87 | 78 | 56 |
| S004 | Aaryan Raut | Male | Dadar |
aaryanraut09@gmail.com | 8369156737 | S004 | Aaryan Raut
| 4| 66 | 63 | 97 | 82 | 55 |
| S005 | Mayank Kale | Male | Dadar |
mayankkale02@gmail.com | 8657272369 | S005 | Mayank
Kale | 1| 79 | 92 | 63 | 93 | 92 |
| S005 | Mayank Kale | Male | Dadar |
mayankkale02@gmail.com | 8657272369 | S005 | Mayank
Kale | 2| 87 | 73 | 53 | 82 | 72 |
| S005 | Mayank Kale | Male | Dadar |
mayankkale02@gmail.com | 8657272369 | S005 | Mayank
Kale | 3| 87 | 52 | 68 | 68 | 88 |
| S005 | Mayank Kale | Male | Dadar |
mayankkale02@gmail.com | 8657272369 | S005 | Mayank
Kale | 4| 85 | 95 | 63 | 63 | 72 |
| S006 | Manushi Desai | Female | Kalyan |
manushidesai05@gmail.com | 9136959310 | S006 | Manushi
Desai | 1| 55 | 56 | 89 | 86 | 75 |
| S006 | Manushi Desai | Female | Kalyan |
manushidesai05@gmail.com | 9136959310 | S006 | Manushi
Desai | 2| 57 | 89 | 98 | 53 | 58 |
| S006 | Manushi Desai | Female | Kalyan |
manushidesai05@gmail.com | 9136959310 | S006 | Manushi
Desai | 3| 67 | 64 | 69 | 74 | 68 |
| S006 | Manushi Desai | Female | Kalyan |
manushidesai05@gmail.com | 9136959310 | S006 | Manushi
Desai | 4| 70 | 73 | 77 | 75 | 84 |
| S007 | Ritika Singh | Female | Thane |
ritikasingh03@gmail.com | 8779961108 | S007 | Ritika Singh
| 1| 59 | 83 | 71 | 91 | 97 |
| S007 | Ritika Singh | Female | Thane |
ritikasingh03@gmail.com | 8779961108 | S007 | Ritika Singh
| 2| 58 | 91 | 53 | 81 | 77 |
| S007 | Ritika Singh | Female | Thane |
ritikasingh03@gmail.com | 8779961108 | S007 | Ritika Singh
| 3| 62 | 69 | 81 | 74 | 81 |
| S007 | Ritika Singh | Female | Thane |
ritikasingh03@gmail.com | 8779961108 | S007 | Ritika Singh
| 4| 89 | 95 | 57 | 87 | 65 |
| S008 | Vaishnavi Shetty | Female | Parel |
vaishnavishetty23@gmail.com | 9819519604 | S008 | Vaishnavi
Shetty | 1| 64 | 50 | 73 | 62 | 92 |
| S008 | Vaishnavi Shetty | Female | Parel |
vaishnavishetty23@gmail.com | 9819519604 | S008 | Vaishnavi
Shetty | 2| 68 | 74 | 70 | 83 | 57 |
| S008 | Vaishnavi Shetty | Female | Parel |
vaishnavishetty23@gmail.com | 9819519604 | S008 | Vaishnavi
Shetty | 3| 61 | 57 | 64 | 55 | 89 |
| S008 | Vaishnavi Shetty | Female | Parel |
vaishnavishetty23@gmail.com | 9819519604 | S008 | Vaishnavi
Shetty | 4| 98 | 84 | 88 | 60 | 76 |
| S009 | Swarangi Kumbhar | Female | Vikhroli |
swarangikumbhar01@gmail.com | 9594745656 | S009 | Swarangi
Kumbhar | 1| 81 | 90 | 96 | 50 | 99 |
| S009 | Swarangi Kumbhar | Female | Vikhroli |
swarangikumbhar01@gmail.com | 9594745656 | S009 | Swarangi
Kumbhar | 2| 68 | 69 | 67 | 85 | 86 |
| S009 | Swarangi Kumbhar | Female | Vikhroli |
swarangikumbhar01@gmail.com | 9594745656 | S009 | Swarangi
Kumbhar | 3| 62 | 65 | 57 | 77 | 52 |
| S009 | Swarangi Kumbhar | Female | Vikhroli |
swarangikumbhar01@gmail.com | 9594745656 | S009 | Swarangi
Kumbhar | 4| 58 | 67 | 58 | 92 | 54 |
| S010 | Ragini | Female | Vadala |
raginiragini04@gmail.com | 8104162336 | S010 | Ragini |
1| 91 | 57 | 65 | 65 | 56 |
| S010 | Ragini | Female | Vadala |
raginiragini04@gmail.com | 8104162336 | S010 | Ragini |
2| 65 | 65 | 69 | 85 | 95 |
| S010 | Ragini | Female | Vadala |
raginiragini04@gmail.com | 8104162336 | S010 | Ragini |
3| 79 | 69 | 85 | 95 | 87 |
| S010 | Ragini | Female | Vadala |
raginiragini04@gmail.com | 8104162336 | S010 | Ragini |
4| 75 | 97 | 71 | 81 | 71 |
+---------+--------------------+--------+----------+-------------------------------+----
--------+---------+--------------------+----------+-----------+-----------+-----------
+-----------+-----------+
40 rows in set (0.00 sec)
mysql> ALTER TABLE student_demo
-> MODIFY total int;
ERROR 1054 (42S22): Unknown column 'total' in 'student_demo'
mysql> ALTER TABLE student_demo
-> ADD total int;
Query OK, 40 rows affected (0.32 sec)
Records: 40 Duplicates: 0 Warnings: 0
mysql> select
personal_demo.Phone,Student_demo.Student_Name,Student_demo
.Subject_5
-> FROM personal_demo
-> JOIN Student_demo ON
personal_demo.Stud_id=Student_demo.Stud_id
-> where Subject_5<=71;
+------------+--------------------+-----------+
| Phone | Student_Name | Subject_5 |
+------------+--------------------+-----------+
| 7715907377 | Demanshu Chaudhari | 54 |
| 9892395141 | Pranav Kankekar | 54 |
| 9892395141 | Pranav Kankekar | 63 |
| 7021447090 | Neeraj Veldandi | 61 |
| 7021447090 | Neeraj Veldandi | 69 |
| 7021447090 | Neeraj Veldandi | 62 |
| 8369156737 | Aaryan Raut | 56 |
| 8369156737 | Aaryan Raut | 55 |
| 9136959310 | Manushi Desai | 58 |
| 9136959310 | Manushi Desai | 68 |
| 8779961108 | Ritika Singh | 65 |
| 9819519604 | Vaishnavi Shetty | 57 |
| 9594745656 | Swarangi Kumbhar | 52 |
| 9594745656 | Swarangi Kumbhar | 54 |
| 8104162336 | Ragini | 56 |
| 8104162336 | Ragini | 71 |
+------------+--------------------+-----------+
16 rows in set (0.00 sec)
mysql> Select
personal_demo.Gender,Student_demo.Semester,Student_demo.AV
G(Subject_1) AS avg_sub_1,Student_demo.AVG(Subject_2) AS
avg_sub_2,Student_demo.AVG(Subject_3) AS
avg_sub_3,Student_demo.AVG(Subject_4) AS
avg_sub_4,Student_demo.AVG(Subject_5) AS avg_sub_5
-> FROM personal_demo
-> JOIN Student_demo ON
personal_demo.Stud_id=Student_demo.Stud_id
-> where Semester=4
-> GROUP BY Gender;
ERROR 1630 (42000): FUNCTION student_demo.AVG does not exist.
Check the 'Function Name Parsing and Resolution' section in the
Reference Manual
mysql> Select personal_demo.Gender,Student_demo.Semester,
-> AVG(Student_demo.Subject_1) AS avg_subj_1,
-> AVG(Student_demo.Subject_1) AS avg_subj_1,
-> AVG(Student_demo.Subject_1) AS avg_subj_1,
-> AVG(Student_demo.Subject_1) AS avg_subj_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 ',' at line 6
mysql> Select personal_demo.Gender,Student_demo.Semester,
-> AVG(Student_demo.Subject_1) AS avg_subj_1,
-> AVG(Student_demo.Subject_2) AS avg_subj_2,
-> AVG(Student_demo.Subject_3) AS avg_subj_3,
-> AVG(Student_demo.Subject_4) AS avg_subj_4,
-> AVG(Student_demo.Subject_5) AS avg_subj_5,
-> FROM personal_demo
-> JOIN Student_demo ON
personal_demo.Stud_id=Student_demo.Stud_id
-> where Semester=4
-> GROUP BY Gender;
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 personal_demo
JOIN Student_demo ON
personal_demo.Stud_id=Student_demo.Stud_' at line 7
mysql> Select personal_demo.Gender,Student_demo.Semester,
-> AVG(Student_demo.Subject_1) AS avg_subj_1,
-> AVG(Student_demo.Subject_2) AS avg_subj_2,
-> AVG(Student_demo.Subject_3) AS avg_subj_3,
-> AVG(Student_demo.Subject_4) AS avg_subj_4,
-> AVG(Student_demo.Subject_5) AS avg_subj_5
-> FROM personal_demo
-> JOIN Student_demo ON
personal_demo.Stud_id=Student_demo.Stud_id
-> where Semester=4
-> GROUP BY Gender;
+--------+----------+------------+------------+------------+------------+------------+
| Gender | Semester | avg_subj_1 | avg_subj_2 | avg_subj_3 |
avg_subj_4 | avg_subj_5 |
+--------+----------+------------+------------+------------+------------+------------+
| Male | 4 | 75.2000 | 70.0000 | 77.2000 | 76.8000 |
65.6000 |
| Female | 4 | 78.0000 | 83.2000 | 70.2000 | 79.0000 |
70.0000 |
+--------+----------+------------+------------+------------+------------+------------+
2 rows in set (0.00 sec)
mysql> select
employee_personal.department,employee_personal.department,em
ployee_personal.department,employee_performance.emp_id,emplo
yee_performance.Performance_rating
-> FROM employee_personal
-> JOIN employee_performance ON
employee_personal.emp_id=employee_performance.emp_id;
+-------------+-------------+-------------+--------+--------------------+
| department | department | department | emp_id |
Performance_rating |
+-------------+-------------+-------------+--------+--------------------+
| EMP001 | 8.5 |
| EMP002 | 9.1 |
| EMP003 | 8.6 |
| EMP004 | 6.2 |
| EMP005 | 0|
| EMP006 | 7.1 |
| EMP007 | 8.3 |
| EMP008 | 5.6 |
| EMP009 | 6.5 |
| EMP010 | 10 |
| EMP011 | 2.7 |
| EMP012 | 0|
| EMP013 | 4.8 |
| EMP014 | 7.5 |
+-------------+-------------+-------------+--------+--------------------+
14 rows in set (0.00 sec)
mysql> select
employee_personal.emp_id,employee_personal.firstname,employee
_personal.department,employee_performance.emp_id,employee_p
erformance.Performance_rating
-> FROM employee_personal
-> JOIN employee_performance ON
employee_personal.emp_id=employee_performance.emp_id;
+--------+-----------+-------------+--------+--------------------+
| emp_id | firstname | department | emp_id | Performance_rating
|
+--------+-----------+-------------+--------+--------------------+
| EMP001 | 8.5 |
| EMP002 | 9.1 |
| EMP003 | 8.6 |
| EMP004 | 6.2 |
| EMP005 | 0|
| EMP006 | 7.1 |
| EMP007 | 8.3 |
| EMP008 | 5.6 |s
| EMP009 | 6.5 |s
| EMP010 | 10 |s
| EMP011 | 2.7 |
| EMP012 | 0|
| EMP013 | 4.8 |
| EMP014 | 7.5 |
+--------+-----------+-------------+--------+--------------------+
14 rows in set (0.00 sec)
mysql> select
-> employee_personal.emp_id,
-> employee_personal.firstname,
-> employee_personal.department,
-> employee_performance.emp_id,
-> employee_performance.Performance_rating,
-> ;
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 '' at line 6
mysql> select
-> employee_personal.emp_id,
-> employee_personal.firstname,
-> employee_personal.department,
-> employee_performance.emp_id,
-> employee_performance.Performance_rating
-> FROM
-> employee_personal
-> JOIN
-> employee_performance ON
employee_personal.emp_id=employee_performance.emp_id;
+--------+-----------+-------------+--------+--------------------+
| emp_id | firstname | department | emp_id | Performance_rating
|
+--------+-----------+-------------+--------+--------------------+
| EMP001 | 8.5 |
| EMP002 | 9.1 |
| EMP003 | 8.6 |
| EMP004 | 6.2 |
| EMP005 | 0|
| EMP006 | 7.1 |
| EMP007 | 8.3 |
| EMP008 | 5.6 |s
| EMP009 | 6.5 |s
| EMP010 | 10 |s
| EMP011 | 2.7 |
| EMP012 | 0|
| EMP013 | 4.8 |
| EMP014 | 7.5 |
+--------+-----------+-------------+--------+--------------------+
14 rows in set (0.00 sec)
mysql> select
employee_personal.firstname,employee_performance.Performance
_rating
-> FROM employee_personal
-> JOIN employee_performance ON
employee_personal.emp_id=employee_performance.emp_id
-> where employee_performance.Performance_rating=0;
+-----------+--------------------+
| firstname | Performance_rating |
+-----------+--------------------+
| Ram | 0|
| Raghav | 0|
+-----------+--------------------+
2 rows in set (0.00 sec)
mysql> SELECT
-> department,
-> COUNT(employee_personal.emp_id)
-> FROM
-> employee_personal
-> GROUP BY
-> department;
+-------------+---------------------------------+
| department | COUNT(employee_personal.emp_id) |
+-------------+---------------------------------+
| 3|
| 2|
| 2|
| 3|
| 2|
| 2|
+-------------+---------------------------------+
6 rows in set (0.00 sec)
mysql> select
emp_id,COUNT(employee_performance.Performance_rating)
-> FROM employee_performance
-> where Performance_rating=8.5;
+--------+------------------------------------------------+
| emp_id | COUNT(employee_performance.Performance_rating) |
+--------+------------------------------------------------+
| EMP001 | 1|
+--------+------------------------------------------------+
1 row in set (0.00 sec)
mysql> select
employee_personal.department,AVG(employee_performance.Perfor
mance_rating) AS avg_performance
-> FROM employee_personal
-> JOIN employee_performance ON
employee_personal.emp_id=employee_performance.emp_id
-> GROUP BY employee_personal.department;
+-------------+--------------------+
| department | avg_performance |
+-------------+--------------------+
| 8.733333587646484 |
| 3.0999999046325684 |
| 7.700000047683716 |
| 7.3666666348775225 |
| 1.350000023841858 |
| 6.150000095367432 |
+-------------+--------------------+
6 rows in set (0.10 sec)
mysql> select
employee_personal.department,AVG(employee_performance.Perfor
mance_rating) AS avg_performance
-> FROM employee_personal
-> JOIN employee_performance ON
employee_personal.emp_id=employee_performance.emp_id
-> GROUP BY employee_personal.department
-> ORDER BY avg_performance DESC
-> lIMIT 1;
+------------+-------------------+
| department | avg_performance |
+------------+-------------------+
| 8.733333587646484 |
+------------+-------------------+
1 row in set (0.00 sec)
mysql> select
-> book_details.book_id,
-> book_details.title,
-> library_transaction.t_id,
-> library_transaction.u_id,
-> library_transaction.address,
-> library_transaction.book_id,
-> library_transaction.borrowed,
-> library_transaction.fine
-> FROM book_details
-> JOIN library_transaction ON
book_details.book_id=library_transaction.book_id;
+---------+----------------+------+------+------------+---------+----------+---------+
| book_id | title | t_id | u_id | address | book_id | borrowed
| fine |
+---------+----------------+------+------+------------+---------+----------+---------+
| 31 | A001 | dadar | 211 | 20 | 200.2 |
| 32 | B002 | bandra | 212 | 30 | 0|
| 33 | C003 | bandra | 213 | 40 | 0|
| 34 | D004 | bandra | 214 | 15 | 0|
| 35 | E005 | bandra | 215 | 60 | 0|
| 36 | F006 | juhu | 216 | 15 | 20.25 |
| 37 | J007 | andheri | 217 | 12 | 0|
| 38 | H008 | malabar hi | 218 | 11 | 0|
| 39 | I006 | goregoan | 219 | 10 | 0|
| 40 | K998 | juhu | 220 | 9 | 500.01 |
| 41 | Z009 | prabhadevi | 221 | 18 | 0|
| 42 | W223 | worli | 222 | 28 | 1000.05 |
+---------+----------------+------+------+------------+---------+----------+---------+
12 rows in set (0.00 sec)
mysql> select
-> book_details.book_id,
-> book_details.title,
-> library_transaction.t_id,
-> library_transaction.u_id,
-> library_transaction.address,
-> library_transaction.book_id,
-> library_transaction.borrowed,
-> library_transaction.fine
-> FROM book_details
-> JOIN library_transaction ON
book_details.book_id=library_transaction.book_id;
+---------+----------------+------+------+------------+---------+----------+---------+
| book_id | title | t_id | u_id | address | book_id | borrowed
| fine |
+---------+----------------+------+------+------------+---------+----------+---------+
| 31 | A001 | dadar | 211 | 20 | 200.2 |
| 31 | A001 | dadar | 211 | 20 | 200.2 |
| 32 | B002 | bandra | 212 | 30 | 0|
| 32 | B002 | bandra | 212 | 30 | 0|
| 33 | C003 | bandra | 213 | 40 | 0|
| 33 | C003 | bandra | 213 | 40 | 500.5 |
| 34 | D004 | bandra | 214 | 15 | 0|
| 34 | D004 | bandra | 214 | 15 | 0|
| 35 | E005 | bandra | 215 | 60 | 0|
| 35 | E005 | bandra | 215 | 60 | 0|
| 36 | F006 | juhu | 216 | 15 | 20.25 |
| 36 | F006 | juhu | 216 | 15 | 20.25 |
| 37 | J007 | andheri | 217 | 12 | 0|
| 37 | J007 | andheri | 217 | 12 | 2000.8 |
| 38 | H008 | malabar hi | 218 | 11 | 0|
| 38 | A001 | dadar | 218 | 11 | 200 |
| 39 | I006 | goregoan | 219 | 10 | 0|
| 39 | A001 | dadar | 219 | 10 | 0|
| 40 | K998 | juhu | 220 | 9 | 500.01 |
| 40 | C003 | bandra | 220 | 9 | 500.01 |
| 41 | Z009 | prabhadevi | 221 | 18 | 0|
| 41 | C003 | bandra | 221 | 18 | 1000.5 |
| 42 | W223 | worli | 222 | 28 | 1000.05 |
| 42 | C003 | bandra | 222 | 28 | 1000.05 |
+---------+----------------+------+------+------------+---------+----------+---------+
24 rows in set (0.00 sec)
mysql> select
personal_demo.Gender,AVG(student_demo.Subject_1) AS
avg_subj_1
-> FROM personal_demo
-> JOIN student_demo ON
personal_demo.Stud_id=student_demo.Stud_id
-> where student_demo.Semester=2
-> GROUP BY personal_demo.Gender;
+--------+------------+
| Gender | avg_subj_1 |
+--------+------------+
| Male | 67.4000 |
| Female | 63.2000 |
+--------+------------+
2 rows in set (0.00 sec)
mysql> select
sales_transaction.product_name,product_details.p_id,product_detai
ls.total
-> FROM sales_transaction
-> JOIN product_details ON
sales_transaction.p_id=product_details.p_id
-> where total=(select MAX(total) from product_details.total);
ERROR 1049 (42000): Unknown database 'product_details'
mysql> select sales_transaction.product_name,product_details.total
-> FROM sales_transaction
-> JOIN product_details ON
sales_transaction.p_id=product_details.p_id
-> where total=(select MAX(total) from product_details.total);
ERROR 1049 (42000): Unknown database 'product_details'
mysql> select
sales_transaction.product_name,product_details.p_id,product_detai
ls.total
-> FROM sales_transaction
-> JOIN product_details ON
sales_transaction.p_id=product_details.p_id
-> where total=(select (MAX(total) from product_details.total);
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 product_details.total)' at line 4
mysql> select
sales_transaction.product_name,product_details.p_id,product_detai
ls.total
-> FROM sales_transaction
-> JOIN product_details ON
sales_transaction.p_id=product_details.p_id;
+--------------+------+---------+
| product_name | p_id | total |
+--------------+------+---------+
| tv | 1001 | 400000 |
| ac | 1002 | 1200000 |
| table | 1003 | 200000 |
| mobile | 1004 | 750000 |
| fridge | 1005 | 300000 |
| chair | 1006 | 20000 |
| jwellery | 1007 | 100000 |
| apple | 1008 | 850 |
| tomato | 1009 | 1300 |
| onion | 1010 | 2250 |
| ladyfinger | 1011 | 3600 |
+--------------+------+---------+
11 rows in set (0.00 sec)
mysql> select
sales_transaction.product_name,product_details.p_id,product_detai
ls.total
-> FROM sales_transaction
-> JOIN product_details ON
sales_transaction.p_id=product_details.p_id
-> ORDER BY product_details.total DESC
-> LIMIT 1;
+--------------+------+---------+
| product_name | p_id | total |
+--------------+------+---------+
| ac | 1002 | 1200000 |
+--------------+------+---------+
1 row in set (0.00 sec)
mysql> select
sales_transaction.product_name,product_details.p_id,product_detai
ls.total
-> FROM sales_transaction
-> JOIN product_details ON
sales_transaction.p_id=product_details.p_id
-> ORDER BY product_details.total DESC;
+--------------+------+---------+
| product_name | p_id | total |
+--------------+------+---------+
| ac | 1002 | 1200000 |
| mobile | 1004 | 750000 |
| tv | 1001 | 400000 |
| fridge | 1005 | 300000 |
| table | 1003 | 200000 |
| jwellery | 1007 | 100000 |
| chair | 1006 | 20000 |
| ladyfinger | 1011 | 3600 |
| onion | 1010 | 2250 |
| tomato | 1009 | 1300 |
| apple | 1008 | 850 |
+--------------+------+---------+
11 rows in set (0.00 sec)
mysql> select
sales_transaction.product_name,product_details.p_id,product_detai
ls.total
-> FROM sales_transaction
-> JOIN product_details ON
sales_transaction.p_id=product_details.p_id
-> ORDER BY product_details.total DESC
-> LIMIT 2;
+--------------+------+---------+
| product_name | p_id | total |
+--------------+------+---------+
| ac | 1002 | 1200000 |
| mobile | 1004 | 750000 |
+--------------+------+---------+
2 rows in set (0.00 sec)