БГ
Size: a a a
БГ
👑️
SELECT DISTINCT to_id, name, text
FROM (
SELECT *
FROM (
select id, from_id as to_id, text
from messages
where to_id == ?
union
select id, to_id, text
from messages
where from_id == ?
)
JOIN users ON
to_id = users.id
ORDER BY id DESC
)
GROUP BY to_id
БГ
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY NOT NULL,
ip TEXT UNIQUE,
name TEXT UNIQUE
);
CREATE TABLE IF NOT EXISTS messages (
id INTEGER PRIMARY KEY NOT NULL,
from_id INTEGER,
to_id INTEGER,
text TEXT,
FOREIGN KEY("from_id") REFERENCES "users"("id"),
FOREIGN KEY("to_id") REFERENCES "users"("id")
);
БГ
БГ
БГ
👑️
SELECT users.name, messages.to_id, messages.text
FROM messages
INNER JOIN users ON users.id=messages.to_id where messages.from_id = ?;
👑️
БГ
SELECT users.name, messages.to_id, messages.text
FROM messages
INNER JOIN users ON users.id=messages.to_id where messages.from_id = ?;
БГ
AT
AT
AT
БГ
БГ
AT
👑️
AT
БГ
БГ