1

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

6 Answers 6

2

I always thought w3schools and Tizag tutorials were pretty good for beginners...

http://www.w3schools.com/sql/default.asp

http://www.tizag.com/mysqlTutorial/

Sign up to request clarification or add additional context in comments.

2 Comments

+1 This person can't just ask there way through life. Learning how to write SQL will be much better for you in the long run then just asking for help for every one.
yeah i understand what your saying but if you read my question maybe you might be able to comprehend that i am more than willing to learn, i simply asked a question so that i may get some help. i am greatful to all those who have helped but for you to make such a comment defies the objective of this website!!!!!! "just learn to programme" is a relevant comment to almost every questionasked on this site, are you going to go around telling evryone this. honestly some people live in small worlds
1

Try:

SELECT hostname, linkedhost_id
FROM rels, hostlist
WHERE host_id = id;

Comments

0

This should do the trick;

SELECT hostname, linked_id FROM hostlist, rels WHERE  rels.host_id = hostlist.id

Comments

0

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.

Comments

0

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.

Comments

0

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.