Combine two tables based on the first table records

Course Queries Syllabus Queries 3 years ago

7.49K 2 0 0 0

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 3 years ago


I have two tables like this,

  Class  |  Name     | Unit  | Year
 --------+-----------+-------+--------
  10th   |  Language |  2    | 2014
  10th   |  Maths    |  3    | 2014

Second table,

      Name  | Title | Period | Syllabus
  ----------+-------+--------+-----------------------------
   Language |Unit1  | 8      | Subject1, Subject2, Subject3
   Language |Unit2  | 9      | Subject4, Subject5, Subject6
    Maths   |Unit1  | 7      | Subject1, Subject2, Subject3
    Maths   |Unit2  | 8      | Subject4, Subject5, Subject6
    Maths   |Unit3  | 9      | Subject5, Subject6, Subject7

And the result Should be,

      Language

      Title | Period | Syllabus
    ----------------------------------
     Unit1  | 8      | Subject1, Subject2, Subject3
     Unit2  | 9      | Subject4, Subject5, Subject6

      Maths

      Title | Period | Syllabus
    ----------------------------------
     Unit1  | 7      | Subject1, Subject2, Subject3
     Unit2  | 8      | Subject4, Subject5, Subject6
     Unit3  | 9      | Subject5, Subject6, Subject7

Second table result is base on the first table name..

Can anyone help me in python with mysql? i'm very to python..

0 views
0 shares

profilepic.png
manpreet 3 years ago
--To get language details:
SELECT title, period, syllabus
FROM Second
WHERE Name = 'Language' --replace language with Maths here to get maths subject details

--To get details from table1 and table2
SELECT s.title, s.period, s.syllabus, r.year
FROM Second s INNER JOIN First f
ON f.Name = s.Name
WHERE Name = 'Language' --replace language with Maths here to get maths subject details
 

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Similar Forum