Q:

MySQL Foreign Keys.. confused

I am trying to understand MySQL Foreign Keys, I hope someone can help.
I have two tables with the following structures;
reports
+-----------+------+-----------+------------------+
|id|user_id |status|report_type|request_id        |
+-----------+------+-----------+------------------+
|                                                 |
+-------------------------------------------------+

users
+-----------+------+-----------+------------------+
|id|username|f_name|l_name     |email             |
+-----------+------+-----------+------------------+
|                                                 |
+-------------------------------------------------+

I have a foreign key in the reprots table (fk_uid) that links the user_id column in the reports table to the id in the users table.
I want to run a MySQL Query in PHP that will pull all the reports for a given user (either by username or user_id, not sure which is best?)
Thanks!

A:

It could be done by simple inner join as
select 
users.username, 
users.f_name, 
users.l_name , 
reports.status,reports.report_type,
reports.request_id from reports
inner join users on users.id = reports.user_id

If you want to search for a specific user then use where condition as
select 
users.username, 
users.f_name, 
users.l_name , 
reports.status,
reports.report_type,
reports.request_id from reports
inner join users on users.id = reports.user_id
where users.username = 'some user name'

And if you want by userid then where condition is 
where users.id = 'your user id'

