S
S
SeiLove2015-11-06 12:29:38
MySQL
SeiLove, 2015-11-06 12:29:38

Wrong database query?

Can anyone tell me what is the query error?

SELECT distinct zzz_1a.tip, zzz_1b.tip, zzz_tip_1a.id_tip, zzz_tip_1b.id_tip, zzz_1a.nomer_kvart,   zzz_1b.nomer_kvart
FROM zzz_1a,zzz_1b,zzz_tip_1a, zzz_tip_1b   
where ((zzz_1a.tip = zzz_tip_1a.id_tip) AND (zzz_tip_1a.kol_komnat=1)) OR ((zzz_1b.tip=zzz_tip_1b.id_tip) AND (zzz_tip_1b.kol_komnat=1))

I have four tables.
zzz_1a, zzz_1b are two tables for apartments.
zzz_tip_1a, zzz_tip_1b are tables that store the structure of these apartments. the relationship is such that the apartment tables have a field tip , which stores the value of the id_tip field of the layout table. And when I want to display all apartments 1a and 1b with the number of rooms = 1... (the number is stored in the structure of the apartment), I get everything in the world at once. I tried to join, but I got confused and it turned out worse ..

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mletov, 2015-11-06
@SeiLove

Don't try to get the whole result at once.
Join zzz_1a and zzz_tip_1a. If the result is correct, then by analogy, do for type b, and then combine the results through UNION.
If wrong, look for the error. In general, decompose into components and simplify.

A
Alexey Tsarapkin, 2015-11-06
@Dreamka

I tried to join, but I got confused and it turned out worse ..

And it is necessary to do JOIN.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question