Reputation: 23
basically i need to write a query for mysql, but i have no experience in this and i cant find good tutorials on the old tinternet.
i have a table called rels
with columns "hosd_id" "linkedhost_id" "text link"
and a table called hostlist with columns "id" "hostname"
all i am trying to achieve is a query which outputs the "hostname" and "linked_id" when "host_id" is equal to "id"
any help or pointers on syntax or code would be helpfull, or even a good mysql query guide
Upvotes: 1
Views: 220
Reputation: 31
Everyone has answered this question correctly, but i also want to post an answer to this. Here's mine:
SELECT hostlist.hostname, rels.linkedhost_id
FROM rels
INNER JOIN hostlist ON (hostlist.id = rels.host_id)
WHERE rels.host_id = hostlist.id;
Upvotes: 0
Reputation: 382656
Try this:
select h.hostname, r.linkedhost_id from rels r inner join hostlist h on
r.hosd_id = h.id where r.host_id = hostlist.id
Finally, have a look at basics of mysql.
Upvotes: 0
Reputation:
I always thought w3schools and Tizag tutorials were pretty good for beginners...
http://www.w3schools.com/sql/default.asp
http://www.tizag.com/mysqlTutorial/
Upvotes: 2
Reputation: 134167
Try:
SELECT h.hostname, r.linkedhost_id
FROM rels r
INNER JOIN hostlist h ON h.id = r.hosd_id
The MySQL documentation has a section on SQL Syntax that is a good start for learning how to write SQL queries.
Upvotes: 0
Reputation: 454960
Try:
SELECT hostname, linkedhost_id
FROM rels, hostlist
WHERE host_id = id;
Upvotes: 1
Reputation: 26350
This should do the trick;
SELECT hostname, linked_id FROM hostlist, rels WHERE rels.host_id = hostlist.id
Upvotes: 0