mysql query query
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 开发者_C百科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
I always thought w3schools and Tizag tutorials were pretty good for beginners...
http://www.w3schools.com/sql/default.asp
http://www.tizag.com/mysqlTutorial/
Try:
SELECT hostname, linkedhost_id
FROM rels, hostlist
WHERE host_id = id;
This should do the trick;
SELECT hostname, linked_id FROM hostlist, rels WHERE rels.host_id = hostlist.id
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.
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.
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;
精彩评论