select
chats.*,
others.first_name,
others.last_name
from chats
inner join chat_participants on chat_participants.chart_id = chats.id and chat_participants.user_id = 1 and chat_participants.is_deleted = false
left join chat_participants as other_participants on other_participants.chart_id = chats.id and other_participants.user_id != 1 and other_participants.is_deleted = false
left join users as others on others.id = other_participants.user_id;
select * from zakaz join objects on objects.id = zakaz.object_id where objects.user_id = 1 order by zakaz.date desc limit 1
select user.id, user.name, max(zakaz.date) as date from user left join objects on objects.user_id = users.id left join zakaz on objects.id = zakaz.object_id group by user.id, user.name
return
$this->faker->randomElement([
['name' => 'Summer Dress', 'image' => 'https://dl.dropbox.com/s/bk1o8dt9rztsvj1/img.png?dl=1'],
['name' => 'Shoulder Bag', 'image' => 'https://dl.dropbox.com/s/bk1o8dt9rztsvj1/img.png?dl=2'],
['name' => 'Warm Hat', 'image' => 'https://dl.dropbox.com/s/bk1o8dt9rztsvj1/img.png?dl=3'],
['name' => 'Black Sneakers', 'image' => 'https://dl.dropbox.com/s/bk1o8dt9rztsvj1/img.png?dl=4'],
['name' => 'Summer Pants', 'image' => 'https://dl.dropbox.com/s/bk1o8dt9rztsvj1/img.png?dl=5'],
['name' => 'T-Shirt', 'image' => 'https://dl.dropbox.com/s/bk1o8dt9rztsvj1/img.png?dl=6'],
]);
SELECT EXISTS (SELECT user_id FROM grade WHERE user_id = 1 and grade = true);
если уж вам надо именно true;falseSELECT
user_id,
COUNT(*) filter(grade = true) AS likes,
COUNT(*) filter(grade = false) AS dislikes
FROM grade
group by user_id;
SELECT
user_id,
COUNT(*) filter(grade = true) AS likes,
COUNT(*) filter(grade = false) AS dislikes
FROM grade
where user_id = 1
group by user_id;
100 | 50 | 1
100 | 50 | 1
не сработает