Please help beginners

Discussion in 'microsoft.public.sqlserver.programming' started by Peterpeter via SQLMonster.com, May 14, 2007.

  1. Table1.F1; F2;F3;..

    Table2.F1; ..
    Table2.F1;..
    Table2.F1;..
    Table2.F1;..

    How to count F1 in Table1 and count F1 in Table2
    F1 is a key column, and I cant use Distinct Count, just Count()

    I used Inner Join, but the result was not correct.
    F1 in Table1=F1 in Table2, but it cant be,
    There must be more F1-s in Table2
     
    Peterpeter via SQLMonster.com, May 14, 2007
    #1
    1. Advertisements

  2. Peterpeter via SQLMonster.com

    Razvan Socol Guest

    Hello, Peter

    Try something like this:

    SELECT
    (SELECT COUNT(F1) FROM Table1) as Cnt1,
    (SELECT COUNT(F1) FROM Table2) as Cnt2

    If this doesn't work for you, please post DDL, sample data and
    expected results, as shown in: http://www.aspfaq.com/etiquette.asp?id=5006

    Also, I'd like to know why you can't use COUNT(DISTINCT...) ?

    Razvan
     
    Razvan Socol, May 14, 2007
    #2
    1. Advertisements

  3. Hey Razvan and thanks :)

    the query is like that

    select
    count(Table1.F2),
    count(Table2.F3)
    from Table1
    inner join Table2
    on Table1.F1=Table2.F1

    I cant use DISTINCT because In Microsoft Query Excel worksheet there is any
     
    Peterpeter via SQLMonster.com, May 15, 2007
    #3
  4. Peterpeter via SQLMonster.com

    Razvan Socol Guest

    Then you should post your question in some other newsgroup, because
    the other solution I posted may not work in "Microsoft Query Excel"
    either, if it doesn't support subqueries (or derived tables). This
    newsgroup is related only to SQL Server.

    Razvan
     
    Razvan Socol, May 15, 2007
    #4
  5. Thanks again
    But I hope. there must be a way to count them in SQL without DISTINCT :)
     
    Peterpeter via SQLMonster.com, May 16, 2007
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.