How to get the name of the table from which rows where found
I am using a mysql stored procedure that checks if an ID is present in 5-6
tables. If any of those tables contains that ID, i set a flag to true.
Finally I select the flag using SELECT.
The parameters to the SP are as follows: ->settings_type = "branch"
->settings_id (the id that is searched) If the searched ID is present in
any of those 6 tables, how can i know from which table the ID was found?
BEGIN DECLARE boolStatus BOOL DEFAULT FALSE;
IF settings_type = "branch"
THEN
IF ((SELECT COUNT(tblbatches.intBranchId) FROM tblbatches
WHERE tblbatches.intBranchId = settings_id > 0) OR
(SELECT COUNT(tblexams.intBranchId) FROM tblexams
WHERE tblexams.intBranchId = settings_id > 0) OR
(SELECT COUNT(tblquestions.intBranchId) FROM tblquestions
WHERE tblquestions.intBranchId = settings_id > 0) OR
(SELECT COUNT(tblresults.intBranchId) FROM tblresults WHERE
tblresults.intBranchId = settings_id > 0) OR
(SELECT COUNT(tblstudents.intBranchId) FROM tblstudents
WHERE tblstudents.intBranchId = settings_id > 0) OR
(SELECT COUNT(tblsubjects.intBranchId) FROM tblsubjects
WHERE tblsubjects.intBranchId = settings_id > 0)
)
THEN
SET boolStatus := TRUE;
END IF;
SELECT boolStatus;
END IF;
END
No comments:
Post a Comment