SELECT id, (c1=1) + (c2=0) + (c3=1) + (c4=1) + (c5=1) + (c6=1) + (c7=1) FROM test
WHERE ((c1=1) + (c2=0) + (c3=1) + (c4=1) + (c5=1) + (c6=1) + (c7=1)) >= 6
;
delete from t
where
exists (
select true
from t tdouble
where
t.user_id = tdouble.user_id
and t.value_1 = tdouble.value_1
and t.value_2 > tdouble.value_2
);
$products_5 = array_slice($products, 0, 5);
$products_more = array_slice($products, 5);
SELECT "conversations".id
FROM "conversations"
JOIN "usersConversations" "uC1" ON "conversations".id = "uC1".conversation_id AND "uC1".user_id = 1
JOIN "usersConversations" "uC2" ON "conversations".id = "uC2".conversation_id AND "uC2".user_id = 2
WHERE "conversations"."isPrivate" = true
ORDER BY "conversations".id DESC
LIMIT 1;
SELECT "conversations".id
FROM "conversations"
WHERE "conversations"."isPrivate" = true
AND EXISTS (SELECT 1 FROM "usersConversations" WHERE "conversations".id = "usersConversations".conversation_id AND "usersConversations".user_id = 1)
AND EXISTS (SELECT 1 FROM "usersConversations" WHERE "conversations".id = "usersConversations".conversation_id AND "usersConversations".user_id = 2)
ORDER BY "conversations".id DESC
LIMIT 1;
TRUNCATE TABLE tbl RESTART IDENTITY;
select regexp_replace(
'1 (111) 111-11-11,1 (111) 111-11-11,1 (111) 111-11-11,1 (111) 111-11-11,1 (111) 111-11-11',
',1',
',8'
) replaced from dual;
$favorites = [103, 105];
$favorite_ids = implode(',', $favorites);
$query = sprintf('SELECT * FROM employees WHERE employee_id IN (%s)', $favorite_ids);
select * from activity order by id asc limit 0, 3;
select * from activity order by id asc limit 3, 3;
SELECT
p.*
FROM
products as p
WHERE
EXISTS (
SELECT 1 FROM product_filter pf WHERE pf.filter_id = 1 AND pf.product_id = p.id
)
AND EXISTS (
SELECT 1 FROM product_filter pf WHERE pf.filter_id = 2 AND pf.product_id = p.id
);