I have been using MySQL for a while, but only with basic queries and some joins. I want to start using Stored Procedures but I am having trouble finding a good resource to help me with what I want to know.
The main thing I want to know is how to check the value of any field in the entire database before returning anything. For example: a table that defines users, and a table that defines what permissions users have. I want to check if there is a certain permission -> user relationship before doing anything.
Here is a simplified table diagram:
Users:
ID | Username
1 | User1
2 | User2
3 | User3
N | UserN
Permissions:
User ID | Permission ID
1 | 1
2 | 1
1 | 2
etc etc
So basically, I want to turn the following pseudo code into a MySQL Routine:
if (SELECT * FROM Permissions WHERE 'User ID' = ? and 'Permission ID' = ? returns at least one row) {
execute privileged sql
return true
}
return false
I know I may be asking a lot here, but any help would be greatly appreciated!