Tell me please. It is necessary to make a sample with a database with this name of the table from which the sample is taken, is formed based on the prefix of the table and the data that are extracted from the table.
Tables: Sites, Chats, and Chat_ID (correspondence tables).
I need to get the site id and the number of unread from this site. I do this:
SELECT s.id AS id, (SELECT COUNT(*) FROM КАК ПОЛУЧИТЬ ИМЯ ТАБЛИЦЫ? AS ch WHERE ch.chat_id = c.id AND status = 0 AND type = 'CLIENT' ) AS unread FROM site AS s LEFT JOIN chat AS c ON c.site_id = s.id AND c.operator_id = s.user_id WHERE s.user_id = 1; The name of the table consists of the prefix and the site id is chat_1.
Maybe this is not correct - do not throw tapkapi)