User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 397,786 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,364 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 1187 | Replies: 5
Reply
Join Date: Jun 2005
Location: USA
Posts: 147
Reputation: ashneet is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
ashneet's Avatar
ashneet ashneet is offline Offline
Junior Poster

Query Help

  #1  
Sep 6th, 2006
Problem:
I have two tables and those two table have one field in common which is "S_ID"

first table have 2 fields:
"S_ID", "T_ID"
second table have these fields:
"S_ID", "First", "Last"
----------------------------------

What i want to do is that i need to extract the the field "S_ID" from the first table and order them by the field "Last" which is in the other table.

any one know how i can do that in one or 2 query.
Also I am using php.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2005
Location: Manchester, UK
Posts: 481
Reputation: pty is on a distinguished road 
Rep Power: 3
Solved Threads: 31
pty's Avatar
pty pty is offline Offline
Posting Pro in Training

Re: Query Help

  #2  
Sep 10th, 2006
Originally Posted by ashneet View Post
Problem:
I have two tables and those two table have one field in common which is "S_ID"

first table have 2 fields:
"S_ID", "T_ID"
second table have these fields:
"S_ID", "First", "Last"
----------------------------------

What i want to do is that i need to extract the the field "S_ID" from the first table and order them by the field "Last" which is in the other table.

any one know how i can do that in one or 2 query.
Also I am using php.


select ft.s_id
from first_table ft
join second_table st on ft.s_id = st.s_id
order by st.s_id
Last edited by pty : Sep 10th, 2006 at 3:15 pm. Reason: code tags
Note to self... pocket cup
Reply With Quote  
Join Date: Jun 2005
Location: USA
Posts: 147
Reputation: ashneet is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
ashneet's Avatar
ashneet ashneet is offline Offline
Junior Poster

Re: Query Help

  #3  
Sep 10th, 2006
Thanks A lot.
That worked really nice.
I never really understood JOIN commands, even if i read the books for SQL they only comfused me more LOL.
Reply With Quote  
Join Date: Oct 2005
Location: Manchester, UK
Posts: 481
Reputation: pty is on a distinguished road 
Rep Power: 3
Solved Threads: 31
pty's Avatar
pty pty is offline Offline
Posting Pro in Training

Re: Query Help

  #4  
Sep 10th, 2006
Originally Posted by ashneet View Post
Thanks A lot.
That worked really nice.
I never really understood JOIN commands, even if i read the books for SQL they only comfused me more LOL.


A join basically combines records from more than one table. This article may help but the best way to understand is to make some test tables and actually have a go at constructing queries that utilise different types of joins.
Note to self... pocket cup
Reply With Quote  
Join Date: Jul 2006
Location: Remunj
Posts: 168
Reputation: pritaeas is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 18
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Junior Poster

Re: Query Help

  #5  
Sep 14th, 2006
SELECT * FROM first, second WHERE first.S_ID=second.S_ID ORDER BY second.Last

Does the same thing, but is much faster than a join.
"Premature optimization is the root of all evil."
Donald Knuth / Tony Hoare
Reply With Quote  
Join Date: Jun 2005
Location: USA
Posts: 147
Reputation: ashneet is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
ashneet's Avatar
ashneet ashneet is offline Offline
Junior Poster

Re: Query Help

  #6  
Sep 14th, 2006
Thanks I will try that too.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MySQL Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the MySQL Forum

All times are GMT -4. The time now is 5:12 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC