If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > query help from two tables..... anyone...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-28-04, 12:23
hallian hallian is offline
Registered User
 
Join Date: Aug 2004
Posts: 2
query help from two tables..... anyone...

hello -

I have two tables called "sites" and "hosts."

This is my hosts table:

id | hostname
===========
1 | athens
2 | soccer
3 | football
4 | baseball

THis is my sites table:

id | host_id_1 | host_id_2 | expires
==============================
1 | 4 | 1 | 2008-12-31
2 | 3 | 2 | 2003-12-12
3 | 2 | 1 | 2005-10-10
4 | 4 | 3 | 2007-10-10



Now, I want to see all records for "athens" which is id=1 from host table. Now, I want to see and matching all instances of id "1" with any other id's from sites tables. I trying to get this.....

baseball - athen - 2008-12-31
soccer - athens - 2005-10-10
Reply With Quote
  #2 (permalink)  
Old 08-28-04, 12:45
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,410
Good for you.
What have you tried?
What were the results?
Here is a free clue that might be part of a correct solution

FROM HOSTS H1, HOSTS H2, SITES
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #3 (permalink)  
Old 08-28-04, 22:26
hallian hallian is offline
Registered User
 
Join Date: Aug 2004
Posts: 2
this is what I have tried... but does not seem to work. Also, need to show the lowest date between the two which I have not figured out yet between the two ID's in the site table.

-----

mysql> select distinct h.hostname, h1.hostname, e.expires from hosts e, hosts h, hosts h1, sites s where (s.host_id_1='1' and h.id='1') and (h.id != h1.id);

+----------+----------+------------+
| hostname | hostname | expires |
+----------+----------+------------+
| master19 | deed | 2007-12-31 |
| master19 | deed | 2005-12-31 |
| master19 | deed | 2006-12-31 |
| master19 | slop | 2007-12-31 |
| master19 | slop | 2005-12-31 |
| master19 | slop | 2006-12-31 |
+----------+----------+------------+
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On