DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   MySQL (http://www.daniweb.com/forums/forum126.html)
-   -   Query Help (http://www.daniweb.com/forums/thread54388.html)

ashneet Sep 6th, 2006 4:08 pm
Query Help
 
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.

pty Sep 10th, 2006 3:15 pm
Re: Query Help
 
Quote:

Originally Posted by ashneet (Post 249954)
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

ashneet Sep 10th, 2006 3:51 pm
Re: Query Help
 
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.

pty Sep 10th, 2006 6:45 pm
Re: Query Help
 
Quote:

Originally Posted by ashneet (Post 251051)
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.

pritaeas Sep 14th, 2006 11:05 am
Re: Query Help
 
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.

ashneet Sep 14th, 2006 11:19 am
Re: Query Help
 
Thanks I will try that too.


All times are GMT -4. The time now is 8:35 am.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC