Run mysql query from two tables

I am trying to create a report but having some issues, I need to pull a from a department column in one table and then take those results and use the login column from that to search in the second table. Can anyone help me with this? Thanks
Who is Participating?
Kevin CrossConnect With a Mentor Chief Technology OfficerCommented:
As stated above, it sounds like you want a JOIN.

SELECT a.asset, a.asignedto
FROM atsassets a
JOIN atsusers u ON u.login = a.asignedto
WHERE u.department = 'departement you want to search'

Giovanni HewardCommented:
You'll need to use a JOIN statement... example:

select * from `db`.`login_table` l
join `db`.`department_table` d on d.`id`=l.`dept_id`;

Open in new window

maximus81Author Commented:
So what would that look like with this information.

Database ATS

Table - atsusers - Colunms - department, login
Table - atsassets - Colunms - asset, asignedto

I want to display the asset name from atsassets and would like to search using the department, this would give me all the logins from atsusers table, next I want to search the atsassets asignedto colunm using the logins from atsusers. This is so confusing.
maximus81Author Commented:
Thank you so much, you have saved me hours of trying to figure this out.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.