1

Topic: How to make sampling of several tables?

Good evening! As it is possible to implement request through select from several tables. Begins with the table subject, the beret idsubject searches in the table company for coincidence idsubject if is not present searches in the table person for coincidence idsubject? I.e. coincidence can be only in one table company or person. When coincidence is found then selects all appropriate fields. How to make such request?

2

Re: How to make sampling of several tables?

Two JOIN and COALESCE on steams of fields from tables.

3

Re: How to make sampling of several tables?

In flow of three hours , such request which does not work turned out

SELECT subject.id_subject FROM subject
LEFT JOIN person on subject.id_subject = person.id_subject
LEFT JOIN company on subject.id_subject = company.id_subject
COALESCE (person.id_subject, company.id_subject) AS result;

4

Re: How to make sampling of several tables?

At first everything that SELECT, and only then FROM. And at you COALESCE for some reason it appeared in a bum.

5

Re: How to make sampling of several tables?

Because I in a bum