There are two types of SOQL queries that we can use :
1. Child
to parent
2. Parent
to child
If you want to get data from child object, then can use
parent to child query. For an example Account and contact have parent- child
relationship. For accessing data from contact query would be like :
List<Account> acc=[select id,Name,(select
id,lastName,firstname from Contact) from Account limit 100];
This query returns 100 accounts and all contacts related to
each account.
Use following reference
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_relationships.htm#understanding_relationships
There are two types of SOQL queries that we can use :
1. Child to parent
2. Parent to child
If you want to get data from child object, then can use parent to child query. For an example Account and contact have parent- child relationship. For accessing data from contact query would be like :
List<Account> acc=[select id,Name,(select id,lastName,firstname from Contact) from Account limit 100];
This query returns 100 accounts and all contacts related to each account.
For more information go through this link-
http://wiki.developerforce.com/index.php/A_Deeper_look_at_SOQL_and_Relationship_Queries_on_Force.com
http://www.salesforce.com/us/developer/docs/api/index_Left.htm#StartTopic=Content/sforce_api_calls_soql.htm
Hope this helps.