M
M
Max Ba2017-06-13 12:18:33
PHP
Max Ba, 2017-06-13 12:18:33

How to make LIMIT on the first table?

Guys, there are two tables, Brands and their cars. One brand has many cars.
How to make LIMIT 0, 2 on Brands table?
So that I can see only two brands and ALL cars for them?

SELECT * 
FROM `brands` t1
LEFT JOIN `auto` t2
ON t2.`id_brand` = t1.`id`
LIMIT 1

Not suitable, because it cuts off the output of the second one.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
romy4, 2017-06-13
@phpcoder81

first select two brands with a simple query and then join this selection to the car table

select * 
from (select ... from brands ... limit 2 ) b 
left join auto ....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question