0

I am a total MySql noob. I have two tables, Computer and Technician. Computer has a foreign key of techID which associates it with a particular Technician entry and indicates which Technician last serviced a computer. Basically I want list the last technician to service every computer.

I thought to do something like:

SELECT techID FROM Computer

My issue is that for each techID in my result set, I want to grab the technician's name out of the Technician table and return that instead. Basically I wondering how to query and achieve the same result as something like:

results = SELECT techID FROM Computer
for-each(r in results){
    SELECT name FROM Technician WHERE techID = r.techID
}
4

1 に答える 1

2

JOIN を使用します。

SELECT     Computer.id, Technician.name
FROM       Computer
INNER JOIN Technician
ON         Computer.techID = Technician.techID 

これにより、技術者が一致する各コンピューターのリストが表示されます。

于 2012-04-25T21:41:00.440 に答える