Skip to content
Advertisement

How to bring columns to a table from another table by the Id?

I have this tables People, Ticket, and Report.

I would like to replace the ForeingKey idPeople with columns Name and Age from People table.

In the Report table replace the Foreing Key idTicket with ticketCol2, Name, Age from the previous table Ticket with replaced columns (idPeople by Name, Age).

And I the result should be like this table and must be done in one query.

I Have tried replacing the foreingkeys with LEFT JOIN and bringing some columns Name and Age to the Ticket table but now the last part where I should replace idTicket with Columns from Ticket is not working.

I have read about the nested JOINs but I cannot understand it very well, I would really appreciate some idea of how I can do it or what should I investigate. Are nested Joins the right way?

The query that I’ve tried to accomplish the Table Ticket.

Advertisement

Answer

Try something like this:

Like @RiggsFolly said, the Ticket.idPeople won´t match to the People.idPeople, so this will not match any rows.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement