Click here to Skip to main content
15,890,399 members
Home / Discussions / Database
   

Database

 
QuestionProblem populating table Pin
TheJudeDude5-Jan-06 5:06
TheJudeDude5-Jan-06 5:06 
AnswerRe: Problem populating table Pin
Colin Angus Mackay5-Jan-06 6:45
Colin Angus Mackay5-Jan-06 6:45 
GeneralRe: Problem populating table Pin
TheJudeDude5-Jan-06 14:38
TheJudeDude5-Jan-06 14:38 
GeneralRe: Problem populating table Pin
Colin Angus Mackay5-Jan-06 20:45
Colin Angus Mackay5-Jan-06 20:45 
GeneralRe: Problem populating table Pin
TheJudeDude7-Jan-06 3:30
TheJudeDude7-Jan-06 3:30 
GeneralRe: Problem populating table Pin
Colin Angus Mackay7-Jan-06 3:42
Colin Angus Mackay7-Jan-06 3:42 
QuestionSQL query Pin
Deian5-Jan-06 4:33
Deian5-Jan-06 4:33 
AnswerRe: SQL query Pin
Colin Angus Mackay5-Jan-06 6:39
Colin Angus Mackay5-Jan-06 6:39 
Deian wrote:
I'm getting the DISTINCT code


This will be
SELECT DISTINCT code FROM Table1


Deian wrote:
and in the same query I want to get the count(*) of records in table1 for each code


We can drop the DISTINCT because we'll be adding a GROUP BY for the aggregation
SELECT code, COUNT(*) as count FROM Table1 GROUP BY code



Deian wrote:
count(*) in table2 where the code equals the code in table1


Now, create a similar query for Table2 and make both subqueries and join on the subqueries.
SELECT t1.code, count1, count2
FROM (SELECT code, COUNT(*) as count1                 -- This select is from the previous step
      FROM Table1
      GROUP BY code) AS t1
INNER JOIN (SELECT code, COUNT(*) as count2           -- Similar but for Table2
            FROM Table1
            GROUP BY code) AS t2 ON t1.code = t2.code -- Join the two subqueries together


Does this help?


ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell

GeneralRe: SQL query Pin
Deian5-Jan-06 7:32
Deian5-Jan-06 7:32 
QuestionRe: SQL query Pin
Deian6-Jan-06 5:22
Deian6-Jan-06 5:22 
QuestionJoin On Null?? Pin
tadhg885-Jan-06 3:05
tadhg885-Jan-06 3:05 
AnswerRe: Join On Null?? Pin
Colin Angus Mackay5-Jan-06 3:28
Colin Angus Mackay5-Jan-06 3:28 
GeneralRe: Join On Null?? Pin
tadhg885-Jan-06 4:42
tadhg885-Jan-06 4:42 
QuestionMSDE 2000 upgrade to SQL Server 2005 Developer Pin
Kevin McFarlane5-Jan-06 2:34
Kevin McFarlane5-Jan-06 2:34 
QuestionProblem with connection pooling Pin
nguyenvhn4-Jan-06 15:51
nguyenvhn4-Jan-06 15:51 
AnswerRe: Problem with connection pooling Pin
S. Akif Kamal4-Jan-06 18:21
S. Akif Kamal4-Jan-06 18:21 
GeneralRe: Problem with connection pooling Pin
nguyenvhn5-Jan-06 16:09
nguyenvhn5-Jan-06 16:09 
Questionkindly help me vb codes.. Pin
Estong Odpaga4-Jan-06 13:11
Estong Odpaga4-Jan-06 13:11 
AnswerRe: kindly help me vb codes.. Pin
ramani.r5-Jan-06 1:31
ramani.r5-Jan-06 1:31 
QuestionConnect to a CSV file Pin
gharry4-Jan-06 10:58
gharry4-Jan-06 10:58 
AnswerRe: Connect to a CSV file Pin
S Douglas4-Jan-06 19:32
professionalS Douglas4-Jan-06 19:32 
GeneralRe: Connect to a CSV file Pin
gharry4-Jan-06 23:01
gharry4-Jan-06 23:01 
GeneralRe: Connect to a CSV file Pin
S Douglas4-Jan-06 23:49
professionalS Douglas4-Jan-06 23:49 
GeneralRe: Connect to a CSV file Pin
gharry4-Jan-06 23:59
gharry4-Jan-06 23:59 
GeneralRe: Connect to a CSV file Pin
S Douglas5-Jan-06 0:02
professionalS Douglas5-Jan-06 0:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.