Home > database >  Which logical ability to look at it
Which logical ability to look at it

Time:09-27

Example: there are two table 1. 2 school student (primary school "id" is a student of a foreign key "s_id")

I want to two tables associated query, data for all school and school of corresponding student data

Then a statement



` ` `
Select
*
The form
School sc, student st
Where sc. Id=student. S_id
` ` `

In the table and then the problem comes when the school has no corresponding student, school data also can not get

And I hope that the result is: whether school corresponds to the student, the school first full access to the data, if there is a corresponding student, at the same time, access student data

Excuse me everybody have any good ideas?

CodePudding user response:

Where school. Id=student. Sid (+) as the connection with your other conditions change

CodePudding user response:

Syntax error, brother

CodePudding user response:

reference 1st floor weixin_38847048 response:
where school. Id=student. Sid (+) as the connection with your other conditions under the variable


Syntax error, brother

CodePudding user response:

Solve!

Select * from school s1 left join student on s1, s2 id=s2_id

This is the truth

CodePudding user response:

(+), the grammar is early, are now this is not recommended, and subsequent versions do not support,

CodePudding user response:

Select * from school sc left join student st on sc. Id=st. s_id

Left join table query, it is the left table sc query, according to the condition of sc. Id=st. s_id cartesian product operation with right table st, no matter how right table st is yao has finally found out the results of the data line number is the same as the left table sc

SQL is a collection of the building Lord query, when two tables have no data intersection, there will be no query results

CodePudding user response:

` ` `
Select
*
The form
School sc, student st
Where sc. Id (+)=student. S_id

CodePudding user response:

(+) is written before the Oracle 8 I, written advice now left the join or rigth join
  • Related