Ask a Question related to ASP, Design and Development.
-
Jeff Uchtman #1
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
-
Bob Barrows #2
Re: Any way I can do this? Should I do this?
Jeff Uchtman wrote:
It's always easiest to use an example to get your idea across. Show us some> 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.
>
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
-
Jeff Uchtman #3
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...some> Jeff Uchtman wrote:> It's always easiest to use an example to get your idea across. Show us> > 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.
> >as> 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> its version.
>
> Bob Barrows
>
>
Jeff Uchtman Guest
-
Bob Barrows #4
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:>> It's always easiest to use an example to get your idea across. Show>>> 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.
>>>
>> 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
-
Jeff Uchtman #5
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
-
Jeff Uchtman #6
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
-
Bob Barrows #7
Re: Any way I can do this? Should I do this?
Jeff Uchtman wrote:
So, using your sample data, the results you want would be as follows?> 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.
>
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
-
Jeff Uchtman #8
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:So, using your sample data, the results you want would be as follows?> 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.
>
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
-
Bob Barrows #9
Re: Any way I can do this? Should I do this?
Jeff Uchtman wrote:
So does my suggested query give you what you want?> Subs name should not be dependent on anything (I think)
> Relationship on Cats table and Subs table is between the Cats_ID.
>
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
-
Jeff Uchtman #10
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:So does my suggested query give you what you want?> Subs name should not be dependent on anything (I think)
> Relationship on Cats table and Subs table is between the Cats_ID.
>
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
-
Bob Barrows #11
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
-
Jeff Uchtman #12
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
-
Bob Barrows #13
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
-
Jeff Uchtman #14
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
-
Jeff Uchtman #15
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
-
Bob Barrows #16
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
-
Jeff Uchtman #17
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
-
Jeff Uchtman #18
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
-
Jeff Uchtman #19
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...ct> 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> 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
-
Jeff Uchtman #20
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...here.> OK, very close. Getting count of 1 on relationship even if nothing isin> 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_NAMEthe> > this query with the assocaiation to the Cat_ID and CAT_NAME giving me> 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



Reply With Quote

