I
I
Igor Belikov2014-03-05 05:17:19
MySQL
Igor Belikov, 2014-03-05 05:17:19

Problem with the right selection?

Perhaps due to the fact that it is already deep in the night, but I am rigidly stupid.
There is a table like this:
ee69b0889c1d4b34a4e95cbec1b80e58.PNG
This is a table that stores users of dialogs.
Accordingly, there is still a table:
dialogs ( id );
messages ( id | user_id | dialog_id | content );
users ( id | name ).
I need to check for the existence of a dialogue between two users, whether there is a dialogue between user_1 and user_2.
Or maybe it can be somehow beautifully displayed using ar yii?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
akashtrih, 2014-03-05
@igorbelikov

Offhand something like this:

SELECT `dl2`.`id` AS `exists`
FROM `dialog_relations` AS `dl`
LEFT JOIN `dialog_relations`  AS `dl2` USING(`dialog_id`)
WHERE `dl`.`user_id` = 1 AND `dl2`.`user_id` = 2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question