tags:

views:

34

answers:

5
+1  Q: 

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 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

A: 

This should do the trick;

SELECT hostname, linked_id FROM hostlist, rels WHERE  rels.host_id = hostlist.id
Adnan
cheers very much mate
A: 

Try:

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

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.

Justin Ethier
thank you my friend , much appreciated
You're welcome, good luck!
Justin Ethier
+1  A: 

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

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

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

W_P
+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.
thecoshman
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
@paul thank you too
A: 

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.

Sarfraz
thank you for you time