add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE logs
SELECT 1 id, 'comments' reference_table, 45 reference_table_id
UNION ALL
SELECt 2, 'reports', 75;
SELECT * FROM logs;
id reference_table reference_table_id
1 comments 45
2 reports 75
SELECT CONCAT( 'SELECT ',
GROUP_CONCAT( CONCAT( reference_table,
'.id AS ',
reference_table,
'_id'
)
),
' FROM ',
GROUP_CONCAT( reference_table ),
' WHERE ',
GROUP_CONCAT( CONCAT( reference_table,
'.id = ',
reference_table_id
)
SEPARATOR ' AND '
)
)
FROM logs
/* WHERE ... */
INTO @sql;
SELECT @sql; -- check the final query text is correct
@sql
SELECT comments.id AS comments_id,reports.id AS reports_id FROM comments,reports WHERE comments.id = 45 AND reports.id = 75