I am having some difficulty trying to use LIMIT in one of my Sub Queries, I ran into the error
MariaDB doesn't yet support 'LIMIT in subquery'
On a query that is similair to what I've done in PostgreSQL in order to get 3 child results for every parent that has a child
select * from parent
join child on child.ch_pa_id = parent.pa_id
and child.ch_id in (
select child.ch_id from child
where child.ch_id = parent.pa_id
limit 3
)
order by parent.pa_id;
I saw that there was a question regarding the same thing here
MySQL - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery
The question has an answer but I am unable to get it work for my needs mainly because I need to do it by row with a join, I tried to apply the same thing to my query but I'm not sure how to keep the join working
select * from parent as p
join (
select * from child
where child.ch_pa_idno = p.pa_idno # this line breaks it
limit 3
) as c on c.ch_pa_id = p.pa_id
order by p.pa_id;
It's giving an error that p.pa_idno is an Unknown column, I'm sure I'm being an idiot and there's something clearly wrong here
EXAMPLE
Here is a working example done with PostgreSQL http://sqlfiddle.com/#!17/4ed4d/2. It is returning only two parent records and for each parent it is returning only 2 child records