SolveErrors
MYSQL

Querying unrelated tables

12 views

I have an inventory database with three tables: hardware, location, and user.
Code:
hardware          location    users
---------------   ---------   --------
hware_id          loc_id      user_id
users_user_id     loc_name    user_name
location_loc_id   etc...      etc...
hware_serial
hware_model
etc...

Hardware is assigned to only one user at only one location. Locations and users have multiple hardware assigned to them, that is why I added the fields to the hardware table to handle the associations. But, I have users that are assigned to multiple locations so I wasn't sure how to create that relationship since a location would have many users and a user could have many locations.

So what I am trying to do is get a list of hardware models (hardware.hware_model) and user names (users.user_name) that hardware is assigned to based on the location (location.loc_name). So it will look like this:
Code:
hware_name | user_name
-----------|----------
MacBook    | Steve Jobs
ThinkPad   | Bill Gate

I don't have anything I have tried yet because I don't know where to begin. I can add more fields or another table if it makes it easier.

More MYSQL fixes

Mysql DumpingNeed help understanding error messageSorting problemMySQL resourcesItalian Characters are stored as "?" in the database.SQL error Not sure why