Hi

This is a pretty long question - so please bear with me.

I'm an SQL beginner and need help with what looks like a very complex query to me. I know how to accomplish the task with a procedural language but would like to learn the SQL way. I have seen the hundred SQL tutorials on various web sites and have read a book or two on SQL - but it looks like I need more help.

I have a few normalised tables

1. STATE
Columns : STATECODE
STATENAME
Sample Data :
30 ABC
31 DEF
32 GHI
33 JKL

2. PARTY
Columns : PARTYCODE
PARTYNAME
PARTYSYMBOL
Sample Data :
AWP All-World-Party Elephant
AAP All-Asia-Party Cow


3. CONSTITUENCY
Columns : CONSTCODE
STATECODE
CONSTNAME
Sample Data :
30004 30 My Constituency
30005 30 Your constituency
30006 30 Our Constituency
31001 31 Their Constituency
31002 32 His Constituency
4. LEADS
Columns : CONSTCODE
LEADPARTYCODE
Sample Data :
30004 AAP
30005 AAP
31001 AAP
31002 AAP
30005 AAP
30006 AWP

This is an election database. The LEADS table has one row per constituency for all constituencies in the CONSTITUENCY table. Yes, I may not need a separate LEADS table - but that is another story.

I want to find out the party position state wise. Using a procedural language, I would first query the state table for a list of constituencies in state "30". Then I would group the LEADS table by LEADPARTYCODE for all those constituencies. Then I would pick up names and symbols for all the parties.

I guess this can be done more efficiently than creating 3 different recordsets and looping through the data.

A sample result set that I would like is

STATENAME PARTYCODE PARTYNAME PARTYSYMBOL LEADING_IN_#
ABC AAP All-Asia-Party Cow 3
ABC AAW All-World-Party Elephant 1


Thanks for reading all this.

Can somebody, please, help me with how to work this out ?

Thanks a million

Regards

Iyer