Good day! I'm trying to select from two tables in one query data. As a matter of fact, you need to get - nook.*, jurnal.company, jurnal.tara, WHERE nook.parent = jurnal.id and jurnal.date - which is in a different DB row, but this line is connected by jurnal.parent . I made two requests that get the data that I need, but I just can not figure out how to combine them into one!

 SELECT nook.*, jurnal.company, jurnal.tara FROM nook, jurnal WHERE nook.parent = jurnal.id AND nook.spisan is NULL OR nook.spisan = 0 SELECT jurnal.date FROM jurnal WHERE jurnal.id IN (SELECT jurnal.parent FROM nook, jurnal WHERE nook.parent = jurnal.id) 

I think for the masters of labor will not help the novice advice)

    1 answer 1

    Use JOIN. It allows including the table with itself. This makes it possible to connect data from different rows of the table into one row of the query result. Only it is necessary to use pseudonyms in order not to get confused.

     SELECT n.*, j1.company, j1.tara, j2.date FROM nook n JOIN jurnal j1 ON n.parent = j1.id JOIN jurnal j2 ON j2.id = j1.parent WHERE n.spisan is NULL OR n.spisan = 0; 
    • Thanks for the answer. Better late than never ))). This problem has already been solved independently. - Anton