Y
Y
Yuriy2016-10-18 12:49:04
MySQL
Yuriy, 2016-10-18 12:49:04

Subscriber SQL query?

Tell me an approximate sql query for this construction:
There are Signatures for Users, Users have signatures for other Users .. you need to display all my Signatures + Signatures of Users for other Users
1.Col = User, 2.Col=
4c56da7db6ef450290c6934aa6e6b6f4.jpg
SubscriptionForUser 1
then the result is this:
2,3,4,3
If we choose for the User = 2 the
result is this :

Массив_ИД_МоиПодписки = SELECT Юзер FROM ТаблицаПодписокЮзеров WHERE Юзер=%d
Массив_ИД_ПодпискиЮзеров = SELECT Юзер FROM ТаблицаПодписокЮзеров WHERE Юзер=Массив_ИД_МоиПодписки 

ОбъединениеМассива(Массив_ИД_МоиПодписки,Массив_ИД_ПодпискиЮзеров)

And how to do it through LEFT JOIN ? )))
approximately
SELECT t1.`ПодпискаНаЮзера`
    FROM `ТаблицаПодписокЮзеров` t1 
    LEFT JOIN (
        SELECT DISTINCT `ПодпискаНаЮзера` AS `parent`
            FROM `ТаблицаПодписокЮзеров`
    ) AS t2 ON t1.`Юзер`= t2.`parent`

and how to insert it here for a specific user?
those.
WHERE `Юзер`=%d

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2016-10-18
@yous

if you understand the problem correctly, then you can do without left join and other things, but just do

SELECT * FROM tablename WHERE col1 = 1 OR col1 IN (SELECT col2 FROM tablename WHERE col1 = 1)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question