Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 30th, 2008, 10:26 AM
Friend of Wrox
 
Join Date: Dec 2006
Posts: 104
Thanks: 9
Thanked 1 Time in 1 Post
Default Select Count from multiple tables


Chaps,

Hope you can help.

Essentially i am trying to select COUNT() from 5 results tables where a user id is present and bring back a single value.

The table names are -

RS10
RS11
RS12
RS13
RS14

and the user id field is called "usrid" which for example would be '10019'

I have little experience with Joining tables and as yet have not found an example which works.

If anyone could assist that would be superb.

Aspless

 
Old January 30th, 2008, 10:32 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Something like this should work, depending on what you want to do you may have to change the Joins:

SELECT
    Count(r1.pk) as RS10,
    Count(r2.pk) as RS11,
    Count(r3.pk) as RS12,
    Count(r4.pk) as RS13,
    Count(r5.pk) as RS14,
from RS10 r1
INNER JOIN RS11 r2 on r1.UserID = r2.UserID
INNER JOIN RS12 r3 on r1.UserID = r3.UserID
INNER JOIN RS13 r4 on r1.UserID = r4.UserID
INNER JOIN RS14 r5 on r1.UserID = r5.UserID
WHERE r1.userID = 10019




================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Select COUNT(*) grstad Classic ASP Basics 5 April 28th, 2006 11:01 AM
Importing Multiple files in Multiple tables Versi Suomi Access 6 June 1st, 2005 08:47 AM
SELECT COUNT as a ROW?? t0ny SQL Language 3 December 8th, 2004 05:31 AM
Select Where Greater Than Count dave.cody@accenture.com SQL Language 3 April 29th, 2004 05:14 AM
Grant SELECT on multiple tables oidhche SQL Server 2000 3 June 16th, 2003 06:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.