CASE WHEN gebruiken:
SELECT *, (
SELECT `TableName` FROM `TableNames` WHERE `TableID`=`IndexType`
) AS `IndexTypeName`,
CASE
WHEN IndexType=1 THEN (SELECT Username FROM Users WHERE IndexRowID=UserID)
WHEN IndexType=2 THEN (SELECT MessageContent FROM Messages WHERE IndexRowID=MessageID)
WHEN IndexType=3 THEN (SELECT CommentContent FROM Comments WHERE IndexRowID=CommentID) END TableValue
ORDER BY `IndexTime` DESC;
De betere oplossing is om de gegevens van die verschillende tabellen in één tabel te plaatsen en de typeid te gebruiken om ze te scheiden