select kasutaja_nimi, eesnimi, perenimi, r_nimetus, seeria_nr, max(paigalduse_aeg) as paigaldus from kasutaja ka right join riistvara ri on ka.id = ri.id right join r_paigaldus r on ka.id = r.kasutaja_id group by kasutaja_nimi, eesnimi, perenimi, seeria_nr, r_nimetus;
This is the output, but I need those values changed. I have ID primary keys for both – kasutaja and riistvara, but I don’t know how to match kasutaja ID 1 with riistvara ID 2 and vice versa.
And the output should be like this:
The R_NIMETUS and SEERIA_NR fields are different on my output what I get with my code.
Advertisement
Answer
you can’t cross the data because you haven’t a logic link between two tables.
You have only one solution, you must change your table structure:
Scenario 1
If you have a parent – child relation, please add a foreign key on child table
Scanerio 2
If you have a n:m relationship, please create a middle table with fks to parent and child table.
So in your query you can use JOIN operations to show correctly your results