Is it possible to get data from one table when necessary data is in the other one(and so on a few times)? I mean, I have to get result, fetch array, pull all the data in php, make another query... and repeat it a several times before I get the wanted result. Could it be done in one query or have you guys got any ideas about optimization for such issue? I've been searching, but I really didn't find anything what makes sense for me.
UPDATE: Thanks! JOIN fixed my problems but I got some more to work on. Let's say I've got tables like this Users:
ID Name
1 Adam
2 John
3 Lana
Roles(with users ids)
ID Name Cleaner Soldier Doctor
1 Ship crew 2 1 3
How can I get my result like: [1,Ship crew,John,Adam,Lana] in php without making many queries? I mean I'd like to load records from another table for a several fields depending on primary key ID.
EDIT: OK I got it, I just needed some practice with mysql. It's not so hard as I thought it could be. Thanks for that join now I know what I was looking for :)