Skip to content

Instantly share code, notes, and snippets.

@azzumed
azzumed / user and user_contacts.sql
Created May 30, 2022 21:30
Postgre user and user_contacts tables
-- ----------------------------
-- Table structure for user_contacts
-- ----------------------------
DROP TABLE IF EXISTS "public"."user_contacts";
CREATE TABLE "public"."user_contacts" (
"id" int8 NOT NULL DEFAULT nextval('user_contacts_id_seq'::regclass),
"user_id" int8 NOT NULL,
"contact_user_id" int8 NOT NULL
)
;
-- Все взаимные контакты пользователя:
SELECT
contact_user_id AS user_contact_id
FROM
user_contacts uc
WHERE
uc.user_id = 1
AND EXISTS (
SELECT
*