By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE prices (`id` INTEGER, `name` VARCHAR(5), `id_user` INTEGER);
INSERT INTO prices (`id`, `name`, `id_user`) VALUES
('1', 'name1', '21'), ('2', 'name2', '21'), ('3', 'name3', '4');
CREATE TABLE id_feed (`id` INTEGER, `id_prices` INTEGER, `price` INTEGER);
INSERT INTO id_feed (`id`, `id_prices`, `price`) VALUES
('1', '1', '30'), ('2', '1', '30'), ('3', '1', '30'), ('4', '2', '30'),
('5', '2', '30'), ('6', '3', '30');
select p.id, p.name, count(*) price_count
from prices p inner join id_feed i
on i.id_prices = p.id
where p.id_user = 21
group by p.id, p.name
id | name | price_count |
---|---|---|
1 | name1 | 3 |
2 | name2 | 2 |
select p.id, p.name, count(*) price_count
from prices p inner join id_feed i
on i.id_prices = p.id
where p.id_user = 4
group by p.id, p.name
id | name | price_count |
---|---|---|
3 | name3 | 1 |