Home > database >  At the same time two tables for query conditions
At the same time two tables for query conditions

Time:09-28

Table 1
Name the class grade teacher
1 1 10 Lin zhang 1
Zhang Lin 2 2 2 11
3 3 12 zhang Chen 3
4 4 13 Lin 4
5 5 14 Lin zhang
Table 2
Name the class grade teacher
1 June 10 Chen li 1
Chen li 2 July 11 2
Chen li 3 8 12 3
4, 9, 13 Chen li 4
5 10 to 14 Chen li

Now to get a result,
From table 1 according to the conditions (teacher) to find the "3" Chen associated records, need to be in the conditions of the "3" Chen lookup table two correlation record, at the same time show

Single table query
Grades, name, select a. a. a. class, teacher b.
From table 1 a left join teachers bon ID=b ID
Where b. teacher='Chen 3'

CodePudding user response:

The original poster is the problem?

CodePudding user response:

reference 1st floor selling fruit net reply:
the original poster is the problem?

From table 1 according to the conditions (teacher) to find the "3" Chen associated records, need to be in "3" Chen query table 2 the relation of the conditions of records,

CodePudding user response:

 select * from t1 a 
Left the join t2 on a. b=b. teacher
Where a. Teacher='3' Chen


Didn't understand the business logic, didn't understand table design train of thought

CodePudding user response:

Sorry, expression is bad,
Have resend

https://bbs.csdn.net/topics/395391961
  • Related