Any way I can do this? Should I do this?

Ask a Question related to ASP, Design and Development.

  1. #1

    Default Any way I can do this? Should I do this?

    I'd like to combine (if possible these two statements drawing from a total
    of 3 tables.

    sql = "SELECT p.Sub_ID, p.Cat_ID, p.Sub_Name, COUNT(c.Sub_ID) as ct FROM
    Subs p LEFT JOIN Links c ON p.Sub_Id = c.Sub_Id GROUP BY p.Sub_ID, p.Cat_ID,
    p.Sub_Name ORDER BY p.Sub_Name"

    sql = "select * from Subs inner join Cats on Cats.Cat_ID=Subs.Cat_ID ORDER
    BY Sub_Name"

    Is it possible? Am I totaly screwed up for even trying? The goal is to
    count the relations ships in the Subs and Links table based on Sub_ID, to
    display needed data from the Subs table, and to display the Cat_name table
    from the Cats table in relationship to the Cat_ID in both the Cats and Subs
    Table.

    Thanks
    Jeff


    Jeff Uchtman Guest

  2. #2

    Default Re: Any way I can do this? Should I do this?

    Jeff Uchtman wrote:
    > I'd like to combine (if possible these two statements drawing from a
    > total of 3 tables.
    >
    > sql = "SELECT p.Sub_ID, p.Cat_ID, p.Sub_Name, COUNT(c.Sub_ID) as ct
    > FROM Subs p LEFT JOIN Links c ON p.Sub_Id = c.Sub_Id GROUP BY
    > p.Sub_ID, p.Cat_ID, p.Sub_Name ORDER BY p.Sub_Name"
    >
    > sql = "select * from Subs inner join Cats on Cats.Cat_ID=Subs.Cat_ID
    > ORDER BY Sub_Name"
    >
    > Is it possible? Am I totaly screwed up for even trying? The goal is
    > to count the relations ships in the Subs and Links table based on
    > Sub_ID, to display needed data from the Subs table, and to display
    > the Cat_name table from the Cats table in relationship to the Cat_ID
    > in both the Cats and Subs Table.
    >
    It's always easiest to use an example to get your idea across. Show us some
    sample data in tabular format, and then show us the results you wish to
    achieve, also using a tabular format (queries return data in tabular form,
    so that really helps us understand what you want).

    And don't forget to tell us what kind of database you are using, as well as
    its version.

    Bob Barrows


    Bob Barrows Guest

  3. #3

    Default Re: Any way I can do this? Should I do this?

    My bad, it was late and I was frustrated.

    The DB is Access 2000. 3 tables named Cats, Subs, and Links. Tables in
    Cats are Cat_Id, Cat_Name, and Cat_Date. Tables in Subs are Sub_Id, Cat_ID
    (relationship to table Cats), Sub_Name, and Sub_Date. Tables in Links are
    Link_ID, Cat_Id, Sub_Id (relationship to table Subs), Link_Name, Link_Disc,
    Link_Url, and Link_Date. The main info I need to draw from the subs table
    needing the Sub_Id, Cat_Id and Sub_Name. I need the relationship in Cats
    table on Cat_Id pulling the Cat_Name, and I need the number of relationships
    between the Subs table and Links table on the Sub_Id in each of those
    tables. Hope this makes sense.

    Thanks
    Jeff
    "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    news:%23L75Z0JlDHA.1072@TK2MSFTNGP09.phx.gbl...
    > Jeff Uchtman wrote:
    > > I'd like to combine (if possible these two statements drawing from a
    > > total of 3 tables.
    > >
    > > sql = "SELECT p.Sub_ID, p.Cat_ID, p.Sub_Name, COUNT(c.Sub_ID) as ct
    > > FROM Subs p LEFT JOIN Links c ON p.Sub_Id = c.Sub_Id GROUP BY
    > > p.Sub_ID, p.Cat_ID, p.Sub_Name ORDER BY p.Sub_Name"
    > >
    > > sql = "select * from Subs inner join Cats on Cats.Cat_ID=Subs.Cat_ID
    > > ORDER BY Sub_Name"
    > >
    > > Is it possible? Am I totaly screwed up for even trying? The goal is
    > > to count the relations ships in the Subs and Links table based on
    > > Sub_ID, to display needed data from the Subs table, and to display
    > > the Cat_name table from the Cats table in relationship to the Cat_ID
    > > in both the Cats and Subs Table.
    > >
    > It's always easiest to use an example to get your idea across. Show us
    some
    > sample data in tabular format, and then show us the results you wish to
    > achieve, also using a tabular format (queries return data in tabular form,
    > so that really helps us understand what you want).
    >
    > And don't forget to tell us what kind of database you are using, as well
    as
    > its version.
    >
    > Bob Barrows
    >
    >

    Jeff Uchtman Guest

  4. #4

    Default Re: Any way I can do this? Should I do this?

    I'm still having trouble understanding. Please provide sample data in
    tabular format:

    table name
    col1 col2 col3 ...
    A 52 23 ...
    B 78 62 ...


    And show the results you wish to obtain from that sample data in the same
    format:

    results
    col1 col2 col3 ...
    row1
    row2

    Thx,
    Bob Barrows

    Jeff Uchtman wrote:
    > My bad, it was late and I was frustrated.
    >
    > The DB is Access 2000. 3 tables named Cats, Subs, and Links. Tables
    > in Cats are Cat_Id, Cat_Name, and Cat_Date. Tables in Subs are
    > Sub_Id, Cat_ID (relationship to table Cats), Sub_Name, and Sub_Date.
    > Tables in Links are Link_ID, Cat_Id, Sub_Id (relationship to table
    > Subs), Link_Name, Link_Disc, Link_Url, and Link_Date. The main info
    > I need to draw from the subs table needing the Sub_Id, Cat_Id and
    > Sub_Name. I need the relationship in Cats table on Cat_Id pulling
    > the Cat_Name, and I need the number of relationships between the Subs
    > table and Links table on the Sub_Id in each of those tables. Hope
    > this makes sense.
    >
    > Thanks
    > Jeff
    > "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    > news:%23L75Z0JlDHA.1072@TK2MSFTNGP09.phx.gbl...
    >> Jeff Uchtman wrote:
    >>> I'd like to combine (if possible these two statements drawing from a
    >>> total of 3 tables.
    >>>
    >>> sql = "SELECT p.Sub_ID, p.Cat_ID, p.Sub_Name, COUNT(c.Sub_ID) as ct
    >>> FROM Subs p LEFT JOIN Links c ON p.Sub_Id = c.Sub_Id GROUP BY
    >>> p.Sub_ID, p.Cat_ID, p.Sub_Name ORDER BY p.Sub_Name"
    >>>
    >>> sql = "select * from Subs inner join Cats on Cats.Cat_ID=Subs.Cat_ID
    >>> ORDER BY Sub_Name"
    >>>
    >>> Is it possible? Am I totaly screwed up for even trying? The goal
    >>> is to count the relations ships in the Subs and Links table based on
    >>> Sub_ID, to display needed data from the Subs table, and to display
    >>> the Cat_name table from the Cats table in relationship to the Cat_ID
    >>> in both the Cats and Subs Table.
    >>>
    >> It's always easiest to use an example to get your idea across. Show
    >> us some sample data in tabular format, and then show us the results
    >> you wish to achieve, also using a tabular format (queries return
    >> data in tabular form, so that really helps us understand what you
    >> want).
    >>
    >> And don't forget to tell us what kind of database you are using, as
    >> well as its version.
    >>
    >> Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows Guest

  5. #5

    Default Re: Any way I can do this? Should I do this?

    OK, here go's;

    Cats
    Cat_ID Cat_Name
    1 Internet
    2 PC
    3 Sports

    Subs
    Sub_ID Cat_ID Sub_Name
    2 1 Software
    3 2 Microsoft
    3 3 Football

    Links
    Link_ID Sub_ID Cat_ID Link_Desc
    1 2 1 Netscape
    2 3 2 Microsoft
    3 3 3 NCAA

    Table relationship between Cats Cat_ID and Subs Cat_ID. Table relationship
    between Subs Sub_ID and Links Sub_ID.

    Needing from Subs draw Sub_ID, Cat_ID, Sub_Name
    Needing from Cats draw Cat_Name
    Needing from Links draw count number of Link_ID that fall under each Sub_ID

    Results

    Cat_ID, Cat_Name, Sub_ID, Sub_Name, count of links ID under each Sub_ID.

    Hope this makes sense.

    Thanks
    Jeff


    "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    news:ulKssyLlDHA.988@TK2MSFTNGP10.phx.gbl...
    > I'm still having trouble understanding. Please provide sample data in
    > tabular format:
    >
    > table name
    > col1 col2 col3 ...
    > A 52 23 ...
    > B 78 62 ...
    >
    >
    > And show the results you wish to obtain from that sample data in the same
    > format:
    >
    > results
    > col1 col2 col3 ...
    > row1
    > row2
    >
    > Thx,
    > Bob Barrows
    >
    > Jeff Uchtman wrote:
    > > My bad, it was late and I was frustrated.
    > >
    > > The DB is Access 2000. 3 tables named Cats, Subs, and Links. Tables
    > > in Cats are Cat_Id, Cat_Name, and Cat_Date. Tables in Subs are
    > > Sub_Id, Cat_ID (relationship to table Cats), Sub_Name, and Sub_Date.
    > > Tables in Links are Link_ID, Cat_Id, Sub_Id (relationship to table
    > > Subs), Link_Name, Link_Disc, Link_Url, and Link_Date. The main info
    > > I need to draw from the subs table needing the Sub_Id, Cat_Id and
    > > Sub_Name. I need the relationship in Cats table on Cat_Id pulling
    > > the Cat_Name, and I need the number of relationships between the Subs
    > > table and Links table on the Sub_Id in each of those tables. Hope
    > > this makes sense.
    > >
    > > Thanks
    > > Jeff
    > > "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    > > news:%23L75Z0JlDHA.1072@TK2MSFTNGP09.phx.gbl...
    > >> Jeff Uchtman wrote:
    > >>> I'd like to combine (if possible these two statements drawing from a
    > >>> total of 3 tables.
    > >>>
    > >>> sql = "SELECT p.Sub_ID, p.Cat_ID, p.Sub_Name, COUNT(c.Sub_ID) as ct
    > >>> FROM Subs p LEFT JOIN Links c ON p.Sub_Id = c.Sub_Id GROUP BY
    > >>> p.Sub_ID, p.Cat_ID, p.Sub_Name ORDER BY p.Sub_Name"
    > >>>
    > >>> sql = "select * from Subs inner join Cats on Cats.Cat_ID=Subs.Cat_ID
    > >>> ORDER BY Sub_Name"
    > >>>
    > >>> Is it possible? Am I totaly screwed up for even trying? The goal
    > >>> is to count the relations ships in the Subs and Links table based on
    > >>> Sub_ID, to display needed data from the Subs table, and to display
    > >>> the Cat_name table from the Cats table in relationship to the Cat_ID
    > >>> in both the Cats and Subs Table.
    > >>>
    > >> It's always easiest to use an example to get your idea across. Show
    > >> us some sample data in tabular format, and then show us the results
    > >> you wish to achieve, also using a tabular format (queries return
    > >> data in tabular form, so that really helps us understand what you
    > >> want).
    > >>
    > >> And don't forget to tell us what kind of database you are using, as
    > >> well as its version.
    > >>
    > >> Bob Barrows
    >
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.
    >
    >

    Jeff Uchtman Guest

  6. #6

    Default Re: Any way I can do this? Should I do this?

    Typo corrected below~

    Cats
    Cat_ID Cat_Name
    1 Internet
    2 PC
    3 Sports

    Subs
    Sub_ID Cat_ID Sub_Name
    2 1 Software
    3 2 Microsoft
    4 3 Football

    Links
    Link_ID Sub_ID Cat_ID Link_Desc
    1 2 1 Netscape
    2 3 2 Microsoft
    3 4 3 NCAA

    Table relationship between Cats Cat_ID and Subs Cat_ID. Table relationship
    between Subs Sub_ID and Links Sub_ID.

    Needing from Subs draw Sub_ID, Cat_ID, Sub_Name
    Needing from Cats draw Cat_Name
    Needing from Links draw count number of Link_ID that fall under each Sub_ID

    Results

    Cat_ID, Cat_Name, Sub_ID, Sub_Name, count of links ID under each Sub_ID.

    Hope this makes sense.

    Thanks
    Jeff




    Jeff Uchtman Guest

  7. #7

    Default Re: Any way I can do this? Should I do this?

    Jeff Uchtman wrote:
    > OK, here go's;
    >
    > Cats
    > Cat_ID Cat_Name
    > 1 Internet
    > 2 PC
    > 3 Sports
    >
    > Subs
    > Sub_ID Cat_ID Sub_Name
    > 2 1 Software
    > 3 2 Microsoft
    > 3 3 Football
    >
    > Links
    > Link_ID Sub_ID Cat_ID Link_Desc
    > 1 2 1 Netscape
    > 2 3 2 Microsoft
    > 3 3 3 NCAA
    >
    > Table relationship between Cats Cat_ID and Subs Cat_ID. Table
    > relationship between Subs Sub_ID and Links Sub_ID.
    >
    > Needing from Subs draw Sub_ID, Cat_ID, Sub_Name
    > Needing from Cats draw Cat_Name
    > Needing from Links draw count number of Link_ID that fall under each
    > Sub_ID
    >
    > Results
    >
    > Cat_ID, Cat_Name, Sub_ID, Sub_Name, count of links ID under each
    > Sub_ID.
    >
    So, using your sample data, the results you want would be as follows?

    CatID Cat_Name Sub_ID Sub_Name LinksCount
    1 Internet 2 Software 1
    2 PC 3 Microsoft 1
    3 Sports 3 Football 1

    Select c.CatID,c.Cat_Name, s.Sub__ID, count(*) LinksCount
    FROM Cats c Inner Join Subs s ON c.Cat_ID = s.Cat_ID
    Inner Join Links l ON s.SubID = l.Sub_ID AND s.Cat_ID = l.Cat_ID
    Group By c.CatID, s.Sub__ID

    Something seems strange with this design, especially that Subs table: why
    does the Sub_Name depend on both the Sub_ID AND the Cat_ID?


    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows Guest

  8. #8

    Default Re: Any way I can do this? Should I do this?

    Subs name should not be dependent on anything (I think)
    Relationship on Cats table and Subs table is between the Cats_ID.

    Jeff

    "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    news:uynaTjMlDHA.1656@tk2msftngp13.phx.gbl...
    Jeff Uchtman wrote:
    > OK, here go's;
    >
    > Cats
    > Cat_ID Cat_Name
    > 1 Internet
    > 2 PC
    > 3 Sports
    >
    > Subs
    > Sub_ID Cat_ID Sub_Name
    > 2 1 Software
    > 3 2 Microsoft
    > 3 3 Football
    >
    > Links
    > Link_ID Sub_ID Cat_ID Link_Desc
    > 1 2 1 Netscape
    > 2 3 2 Microsoft
    > 3 3 3 NCAA
    >
    > Table relationship between Cats Cat_ID and Subs Cat_ID. Table
    > relationship between Subs Sub_ID and Links Sub_ID.
    >
    > Needing from Subs draw Sub_ID, Cat_ID, Sub_Name
    > Needing from Cats draw Cat_Name
    > Needing from Links draw count number of Link_ID that fall under each
    > Sub_ID
    >
    > Results
    >
    > Cat_ID, Cat_Name, Sub_ID, Sub_Name, count of links ID under each
    > Sub_ID.
    >
    So, using your sample data, the results you want would be as follows?

    CatID Cat_Name Sub_ID Sub_Name LinksCount
    1 Internet 2 Software 1
    2 PC 3 Microsoft 1
    3 Sports 3 Football 1

    Select c.CatID,c.Cat_Name, s.Sub__ID, count(*) LinksCount
    FROM Cats c Inner Join Subs s ON c.Cat_ID = s.Cat_ID
    Inner Join Links l ON s.SubID = l.Sub_ID AND s.Cat_ID = l.Cat_ID
    Group By c.CatID, s.Sub__ID

    Something seems strange with this design, especially that Subs table: why
    does the Sub_Name depend on both the Sub_ID AND the Cat_ID?


    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.



    Jeff Uchtman Guest

  9. #9

    Default Re: Any way I can do this? Should I do this?

    Jeff Uchtman wrote:
    > Subs name should not be dependent on anything (I think)
    > Relationship on Cats table and Subs table is between the Cats_ID.
    >
    So does my suggested query give you what you want?

    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows Guest

  10. #10

    Default Re: Any way I can do this? Should I do this?

    Close, till getting this error:
    [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in
    query expression 'count(*) LinksCount'.

    Jeff

    "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    news:u6fc6CNlDHA.684@TK2MSFTNGP09.phx.gbl...
    Jeff Uchtman wrote:
    > Subs name should not be dependent on anything (I think)
    > Relationship on Cats table and Subs table is between the Cats_ID.
    >
    So does my suggested query give you what you want?

    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.



    Jeff Uchtman Guest

  11. #11

    Default Re: Any way I can do this? Should I do this?

    You should be testing this query in Access, using the query builder (switch
    to SQL View), before you even think of trying to execute it from asp. You'll
    probably get a better error message.
    As a guess, either of the following changes should help:

    Try this first:
    count(*) As LinksCount

    then, if that still causes an error:
    count(l.*) As LinksCount

    FWIW, you should be using the native Jet OLEDB provider in your asp
    connection string, instead of the obsolete ODBC driver. See
    [url]www.connectionstrings.com[/url] for an example.

    Bob Barrows


    Jeff Uchtman wrote:
    > Close, till getting this error:
    > [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing
    > operator) in query expression 'count(*) LinksCount'.
    >
    > Jeff
    >
    > "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    > news:u6fc6CNlDHA.684@TK2MSFTNGP09.phx.gbl...
    > Jeff Uchtman wrote:
    >> Subs name should not be dependent on anything (I think)
    >> Relationship on Cats table and Subs table is between the Cats_ID.
    >>
    >
    > So does my suggested query give you what you want?
    >
    > Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows Guest

  12. #12

    Default Re: Any way I can do this? Should I do this?

    Thanks Bob. I guess I don't have enough knowledge on Access or ASP to do
    this. I do get the same error in the page as query in Access. Tried your
    suggestions and now get [Microsoft][ODBC Microsoft Access Driver] Extra ) in
    query expression 'count(1*) LinksCount'. Will look at your suggestion on
    the connection string.

    Jeff
    "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    news:e5dsneNlDHA.2592@TK2MSFTNGP10.phx.gbl...
    You should be testing this query in Access, using the query builder (switch
    to SQL View), before you even think of trying to execute it from asp. You'll
    probably get a better error message.
    As a guess, either of the following changes should help:

    Try this first:
    count(*) As LinksCount

    then, if that still causes an error:
    count(l.*) As LinksCount

    FWIW, you should be using the native Jet OLEDB provider in your asp
    connection string, instead of the obsolete ODBC driver. See
    [url]www.connectionstrings.com[/url] for an example.

    Bob Barrows


    Jeff Uchtman wrote:
    > Close, till getting this error:
    > [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing
    > operator) in query expression 'count(*) LinksCount'.
    >
    > Jeff
    >
    > "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    > news:u6fc6CNlDHA.684@TK2MSFTNGP09.phx.gbl...
    > Jeff Uchtman wrote:
    >> Subs name should not be dependent on anything (I think)
    >> Relationship on Cats table and Subs table is between the Cats_ID.
    >>
    >
    > So does my suggested query give you what you want?
    >
    > Bob Barrows
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.



    Jeff Uchtman Guest

  13. #13

    Default Re: Any way I can do this? Should I do this?

    I forgot: Access (Jet) is very picky about multiple joins. there has to be
    parentheses around each subjoin. The correct query looks like this:

    Select c.Cat_ID,First(c.Cat_Name) AS [Cat_Name], s.Sub_ID,
    count(*) AS LinkCount
    FROM (Cats c INNER JOIN Subs s ON c.Cat_ID = s.Cat_ID)
    INNER JOIN Links l ON
    s.Cat_ID = l.Cat_ID AND s.Sub_ID = l.Sub_ID
    Group By c.Cat_ID, s.Sub_ID

    The best way to get these groupings right is to use the Access Query Builder
    in Design View and use the GUI to create the joins. Switch to SQL View to
    see the corresponding SQL statement.

    HTH,
    Bob Barrows


    Jeff Uchtman wrote:
    > Thanks Bob. I guess I don't have enough knowledge on Access or ASP
    > to do this. I do get the same error in the page as query in Access.
    > Tried your suggestions and now get [Microsoft][ODBC Microsoft Access
    > Driver] Extra ) in query expression 'count(1*) LinksCount'. Will
    > look at your suggestion on the connection string.
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows Guest

  14. #14

    Default Re: Any way I can do this? Should I do this?

    YAHOOOOOOOO That is EXACTLY what I want. I was just doing the same (like I
    knew what I was doing) in query analyzer. Thanks your the asp session.
    Where do I send the tuition check.

    Jeff
    "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    news:u1vOBzOlDHA.1084@tk2msftngp13.phx.gbl...
    I forgot: Access (Jet) is very picky about multiple joins. there has to be
    parentheses around each subjoin. The correct query looks like this:

    Select c.Cat_ID,First(c.Cat_Name) AS [Cat_Name], s.Sub_ID,
    count(*) AS LinkCount
    FROM (Cats c INNER JOIN Subs s ON c.Cat_ID = s.Cat_ID)
    INNER JOIN Links l ON
    s.Cat_ID = l.Cat_ID AND s.Sub_ID = l.Sub_ID
    Group By c.Cat_ID, s.Sub_ID

    The best way to get these groupings right is to use the Access Query Builder
    in Design View and use the GUI to create the joins. Switch to SQL View to
    see the corresponding SQL statement.

    HTH,
    Bob Barrows


    Jeff Uchtman wrote:
    > Thanks Bob. I guess I don't have enough knowledge on Access or ASP
    > to do this. I do get the same error in the page as query in Access.
    > Tried your suggestions and now get [Microsoft][ODBC Microsoft Access
    > Driver] Extra ) in query expression 'count(1*) LinksCount'. Will
    > look at your suggestion on the connection string.
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.



    Jeff Uchtman Guest

  15. #15

    Default Re: Any way I can do this? Should I do this?

    OK Bob, you got me this far. I made a few changes in the Access query and
    added the Sub_Name. Can I get this to display all fields even if this is no
    present relationship, i.e all the sub_names and Id's? Her is what I
    changed;

    SELECT c.Cat_ID, First(c.Cat_Name) AS Cat_Name, s.Sub_ID, s.Sub_Name,
    count(*) AS ct
    FROM (Cats AS c INNER JOIN Subs AS s ON c.Cat_ID=s.Cat_ID) INNER JOIN Links
    AS l ON (s.Sub_ID=l.Sub_ID) AND (s.Cat_ID=l.Cat_ID)
    GROUP BY c.Cat_ID, s.Sub_ID, s.Sub_Name;

    Thanks again
    Jeff
    "Jeff Uchtman" <uchtman@megavision.com> wrote in message
    news:%23GT1K4OlDHA.1408@TK2MSFTNGP11.phx.gbl...
    YAHOOOOOOOO That is EXACTLY what I want. I was just doing the same (like I
    knew what I was doing) in query analyzer. Thanks your the asp session.
    Where do I send the tuition check.

    Jeff
    "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    news:u1vOBzOlDHA.1084@tk2msftngp13.phx.gbl...
    I forgot: Access (Jet) is very picky about multiple joins. there has to be
    parentheses around each subjoin. The correct query looks like this:

    Select c.Cat_ID,First(c.Cat_Name) AS [Cat_Name], s.Sub_ID,
    count(*) AS LinkCount
    FROM (Cats c INNER JOIN Subs s ON c.Cat_ID = s.Cat_ID)
    INNER JOIN Links l ON
    s.Cat_ID = l.Cat_ID AND s.Sub_ID = l.Sub_ID
    Group By c.Cat_ID, s.Sub_ID

    The best way to get these groupings right is to use the Access Query Builder
    in Design View and use the GUI to create the joins. Switch to SQL View to
    see the corresponding SQL statement.

    HTH,
    Bob Barrows


    Jeff Uchtman wrote:
    > Thanks Bob. I guess I don't have enough knowledge on Access or ASP
    > to do this. I do get the same error in the page as query in Access.
    > Tried your suggestions and now get [Microsoft][ODBC Microsoft Access
    > Driver] Extra ) in query expression 'count(1*) LinksCount'. Will
    > look at your suggestion on the connection string.
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.




    Jeff Uchtman Guest

  16. #16

    Default Re: Any way I can do this? Should I do this?

    I'm confused. What does this query show you? What do you want it to show
    you? Tabular format please.

    Bob Barrows

    Jeff Uchtman wrote:
    > OK Bob, you got me this far. I made a few changes in the Access
    > query and added the Sub_Name. Can I get this to display all fields
    > even if this is no present relationship, i.e all the sub_names and
    > Id's? Her is what I changed;
    >
    > SELECT c.Cat_ID, First(c.Cat_Name) AS Cat_Name, s.Sub_ID, s.Sub_Name,
    > count(*) AS ct
    > FROM (Cats AS c INNER JOIN Subs AS s ON c.Cat_ID=s.Cat_ID) INNER JOIN
    > Links AS l ON (s.Sub_ID=l.Sub_ID) AND (s.Cat_ID=l.Cat_ID)
    > GROUP BY c.Cat_ID, s.Sub_ID, s.Sub_Name;
    >
    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.


    Bob Barrows Guest

  17. #17

    Default Re: Any way I can do this? Should I do this?

    It show only the subs that have a related link below them. If there is no
    relating link they do not show up.
    Jeff


    "Bob Barrows" <reb01501@NOyahoo.SPAMcom> wrote in message
    news:uhHAZKPlDHA.2068@TK2MSFTNGP09.phx.gbl...
    > I'm confused. What does this query show you? What do you want it to show
    > you? Tabular format please.
    >
    > Bob Barrows
    >
    > Jeff Uchtman wrote:
    > > OK Bob, you got me this far. I made a few changes in the Access
    > > query and added the Sub_Name. Can I get this to display all fields
    > > even if this is no present relationship, i.e all the sub_names and
    > > Id's? Her is what I changed;
    > >
    > > SELECT c.Cat_ID, First(c.Cat_Name) AS Cat_Name, s.Sub_ID, s.Sub_Name,
    > > count(*) AS ct
    > > FROM (Cats AS c INNER JOIN Subs AS s ON c.Cat_ID=s.Cat_ID) INNER JOIN
    > > Links AS l ON (s.Sub_ID=l.Sub_ID) AND (s.Cat_ID=l.Cat_ID)
    > > GROUP BY c.Cat_ID, s.Sub_ID, s.Sub_Name;
    > >
    >
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.
    >
    >


    Jeff Uchtman Guest

  18. #18

    Default Re: Any way I can do this? Should I do this?

    Here is what I am seeing: I'd like to see all the SUB_ID and SUB_NAME in
    this query with the assocaiation to the Cat_ID and CAT_NAME giving me the ct
    for links even if 0.

    Jeff


    Description:


    SQL Command:

    SELECT
    c.CAT_ID,
    FIRST(c.CAT_NAME) AS
    Cat_Name,
    s.SUB_ID,
    s.SUB_NAME,
    COUNT(*) AS ct
    FROM
    (Cats c

    INNER JOIN (Subs s
    INNER JOIN Links l ON
    s.CAT_ID = l.CAT_ID AND

    s.SUB_ID = l.SUB_ID) ON
    c.CAT_ID = s.CAT_ID)
    GROUP BY
    c.CAT_ID,

    c.CAT_NAME,
    s.SUB_ID,
    s.SUB_NAME
    QUERY: TEST \ New Query COUNT: 6 record(s)

    CAT_ID Cat_Name SUB_ID SUB_NAME ct
    1 Arts & Humanities 1 Literature 4
    1 Arts & Humanities 2 Photography 6
    2 Business & Economy 4 Shopping 1
    4 Education 7 College & University 1
    4 Education 8 K-12 1
    8 News & Media 16 TV 1
    10 Reference 20 Libraries 1



    Jeff Uchtman Guest

  19. #19

    Default Re: Any way I can do this? Should I do this?

    OK, very close. Getting count of 1 on relationship even if nothing is here.
    Other counts are correct. The only problem is the count of 1 even if not
    there. Here is what I have;

    SELECT
    c.CAT_ID,
    FIRST(c.CAT_NAME) AS Cat_Name,
    s.SUB_ID,
    s.SUB_NAME,
    COUNT(*) AS ct
    FROM
    (Cats c
    INNER JOIN (Subs s
    LEFT JOIN Links l ON
    s.SUB_ID = l.SUB_ID AND
    s.CAT_ID = l.CAT_ID) ON
    c.CAT_ID = s.CAT_ID)
    GROUP BY
    c.CAT_ID,
    c.CAT_NAME,
    s.SUB_ID,
    s.SUB_NAME
    ORDER BY
    s.SUB_NAME



    "Jeff Uchtman" <uchtman@megavision.com> wrote in message
    news:ucIDqMRlDHA.2080@TK2MSFTNGP10.phx.gbl...
    > Here is what I am seeing: I'd like to see all the SUB_ID and SUB_NAME in
    > this query with the assocaiation to the Cat_ID and CAT_NAME giving me the
    ct
    > for links even if 0.
    >
    > Jeff
    >
    >
    > Description:
    >
    >
    > SQL Command:
    >
    > SELECT
    > c.CAT_ID,
    > FIRST(c.CAT_NAME) AS
    > Cat_Name,
    > s.SUB_ID,
    > s.SUB_NAME,
    > COUNT(*) AS ct
    > FROM
    > (Cats c
    >
    > INNER JOIN (Subs s
    > INNER JOIN Links l ON
    > s.CAT_ID = l.CAT_ID AND
    >
    > s.SUB_ID = l.SUB_ID) ON
    > c.CAT_ID = s.CAT_ID)
    > GROUP BY
    > c.CAT_ID,
    >
    > c.CAT_NAME,
    > s.SUB_ID,
    > s.SUB_NAME
    > QUERY: TEST \ New Query COUNT: 6 record(s)
    >
    > CAT_ID Cat_Name SUB_ID SUB_NAME ct
    > 1 Arts & Humanities 1 Literature 4
    > 1 Arts & Humanities 2 Photography 6
    > 2 Business & Economy 4 Shopping 1
    > 4 Education 7 College & University 1
    > 4 Education 8 K-12 1
    > 8 News & Media 16 TV 1
    > 10 Reference 20 Libraries 1
    >
    >
    >

    Jeff Uchtman Guest

  20. #20

    Default Re: Any way I can do this? Should I do this?

    GOT IT!! All is well. Changed COUNT(*) to COUNT(l.Cat_Id). Thanks Bob for
    your input, help guidance, and for all around being a nice guy!

    Jeff


    "Jeff Uchtman" <uchtman@megavision.com> wrote in message
    news:uamv8$RlDHA.2216@TK2MSFTNGP12.phx.gbl...
    > OK, very close. Getting count of 1 on relationship even if nothing is
    here.
    > Other counts are correct. The only problem is the count of 1 even if not
    > there. Here is what I have;
    >
    > SELECT
    > c.CAT_ID,
    > FIRST(c.CAT_NAME) AS Cat_Name,
    > s.SUB_ID,
    > s.SUB_NAME,
    > COUNT(*) AS ct
    > FROM
    > (Cats c
    > INNER JOIN (Subs s
    > LEFT JOIN Links l ON
    > s.SUB_ID = l.SUB_ID AND
    > s.CAT_ID = l.CAT_ID) ON
    > c.CAT_ID = s.CAT_ID)
    > GROUP BY
    > c.CAT_ID,
    > c.CAT_NAME,
    > s.SUB_ID,
    > s.SUB_NAME
    > ORDER BY
    > s.SUB_NAME
    >
    >
    >
    > "Jeff Uchtman" <uchtman@megavision.com> wrote in message
    > news:ucIDqMRlDHA.2080@TK2MSFTNGP10.phx.gbl...
    > > Here is what I am seeing: I'd like to see all the SUB_ID and SUB_NAME
    in
    > > this query with the assocaiation to the Cat_ID and CAT_NAME giving me
    the
    > ct
    > > for links even if 0.
    > >
    > > Jeff
    > >
    > >
    > > Description:
    > >
    > >
    > > SQL Command:
    > >
    > > SELECT
    > > c.CAT_ID,
    > > FIRST(c.CAT_NAME) AS
    > > Cat_Name,
    > > s.SUB_ID,
    > > s.SUB_NAME,
    > > COUNT(*) AS ct
    > > FROM
    > > (Cats c
    > >
    > > INNER JOIN (Subs s
    > > INNER JOIN Links l ON
    > > s.CAT_ID = l.CAT_ID AND
    > >
    > > s.SUB_ID = l.SUB_ID) ON
    > > c.CAT_ID = s.CAT_ID)
    > > GROUP BY
    > > c.CAT_ID,
    > >
    > > c.CAT_NAME,
    > > s.SUB_ID,
    > > s.SUB_NAME
    > > QUERY: TEST \ New Query COUNT: 6 record(s)
    > >
    > > CAT_ID Cat_Name SUB_ID SUB_NAME ct
    > > 1 Arts & Humanities 1 Literature 4
    > > 1 Arts & Humanities 2 Photography 6
    > > 2 Business & Economy 4 Shopping 1
    > > 4 Education 7 College & University 1
    > > 4 Education 8 K-12 1
    > > 8 News & Media 16 TV 1
    > > 10 Reference 20 Libraries 1
    > >
    > >
    > >
    >
    >

    Jeff Uchtman Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139