?
Solved

How to write a join sql query for following conditions.

Posted on 2010-11-25
4
Medium Priority
?
157 Views
Last Modified: 2012-08-14
1.Table 1
Txnenrollment contains familyid,enrolled,cardsprinted,personalized,pcode,blockcode.
2.Table 2
Txnissuance contains those familyid which will be there in txnenrollment
and will have status enrolled=1 and personalized=1 and cardsprinted=1
3.Table 3
mstpanchayat will contain pcode and pname
4.Table 4
mstblock will contain blockcode and blockname
I want to list blockname,pname and count of total enrolled,total personalized and total cardsprinted with a check where all familyid should exist in txnissuance.
0
Comment
Question by:searchsanjaysharma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Expert Comment

by:Andre412
ID: 34214018

Can you give more information about the relationships between the tables
0
 
LVL 6

Accepted Solution

by:
rkannan2000 earned 1500 total points
ID: 34214310
This might help you....

SELECT D.BLOCK_NAME, C.PNAME, SUM(A.ENROLLED),SUM(A.PERSONALIZED),SUM(A.CARDHOLDER), COUNT(A.FAMILY_ID)-COUNT(B.FAMILY_ID)
FROM Txnenrollment A
LEFT OUTER JOIN Txnissuance B ON A.FAMILY_ID=B.FAMIL_ID
JOIN mstpanchayat C ON C.PCODE=A.PCODE
JOIN mstblock D ON D.BLOCKCODE=A.BLOCKCODE
GROUP BY D.BLOCK_NAME, C.PNAME
0
 

Author Comment

by:searchsanjaysharma
ID: 34215298
pcode is primary key in mstpanchayat,
blockcode is primary key in mstblock
and pcode and blockcode exists in txnenrollment
and txnissuance will have only those familyid
which will exist in txnenrollment and will have status of enrolled=1 and personalized=1 and cardsprinted=1
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 37767131
ok
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question