I have 2 tables one typesand the other platesthat are the following:
But I want to bring the typeone from that plate, how would I do it?
Example: I have a dish with the id 1 and it has the id_type 2, and I want to bring the name of that typeor, failing that, the tuplacomplete of thattype
Work with JOINto join the 2 tables since they have in common the id_typeand to filter by a specific value that you give it uses whereto delimit where you want the search to be made.
From the perspective of a Cartesian plane, using JOINor aka INNER JOINwill return results that are linked in both tables; that is, in a scenario where a users table is linked to a posts table; this JOINwill return all users who have registered posts, omitting both users without posts and posts without users
** EXAMPLE **
SELECT types.name, plates.name
FROM types
JOIN plates ON types.id = plates.id_type
WHERE plates.id = 1;
The value 1 that you put replace it with the variable or the exact value that you want to help filter your search; Preferably for each field that you consult, precede it by the name of the table to which it belongs to avoid ambiguities; thus:tablaName.columnaName
Work with
JOIN
to join the 2 tables since they have in common theid_type
and to filter by a specific value that you give it useswhere
to delimit where you want the search to be made.From the perspective of a Cartesian plane, using
JOIN
or akaINNER JOIN
will return results that are linked in both tables; that is, in a scenario where a users table is linked to a posts table; thisJOIN
will return all users who have registered posts, omitting both users without posts and posts without users** EXAMPLE **