Answer the question
In order to leave comments, you need to log in
Help with MySQL query?
Good evening. Need help with a request.
The car_mark table contains the id_car_mark field and the name field.
A query is obtained to get id_car_mark by name
select id_car_mark from car_mark where name='AC'
And the second query is obtained if id_car_mark is received in the first table
select * from car_model where id_car_mark='1'
How to combine this query through INNER so as not to write 2 queries, conditionally get id by name from the first table and find all models from second by received Id
Answer the question
In order to leave comments, you need to log in
SELECT cm.*
FROM
car_mark mk
LEFT JOIN car_model ml ON ml.id_car_mark = mk.id_car_mark
WHERE mk.name = 'AC'
provided that mk.id_car_mark
is a unique value. Otherwise, something likeSELECT ml.*
FROM car_model ml
WHERE ml.id_car_mark = (
SELECT mk.id_car_mark
FROM car_mark mk
WHERE mk.name = 'AC'
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question