I have the following query to output data to a table:

SELECT j.id AS jid, j.product_id AS pid, j.user_id AS wid, j.datex AS jdate, j.count AS count, j.storage_id AS storage_id, u.id AS uid, u.name AS login, u.group_id AS groupn, p.name AS product_name, p.id AS proid FROM s_reports AS j, s_users AS u, s_products AS p WHERE j.user_id = u.id AND j.product_id = p.id 

It is necessary to display u.name from the s_users table, where s_reports.storage_id == s_users.id . I fight, but I don’t get the desired result.

    1 answer 1

    If I correctly understood the required, then

     SELECT j.id AS jid, j.product_id AS pid, j.user_id AS wid, j.datex AS jdate, j.count AS count, j.storage_id AS storage_id, u.id AS uid, u.name AS login, u.group_id AS groupn, p.name AS product_name, p.id AS proid, u2.name FROM s_reports AS j, s_users AS u, s_products AS p, s_users AS u2 WHERE j.user_id = u.id AND j.product_id = p.id AND j.storage_id = u2.id