| | |
Nested loop
Please support our ASP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
Oh okay that's how you have it set. Yeah that is fine. Not highly recommended, but it works. Okay then try this query:
You have to lost the DISTINCT, otherwise you will only grab One Top Category, which means you only grab one MiddleCategory. Drop the destinct, and no need for the MCLink.
And now your thing should work.
ASP Syntax (Toggle Plain Text)
SQL = "SELECT TC.topcategory, MC.middlecategory "&_ "FROM tbtopcategory TC, tbmiddlecategory MC, tbconnectcategory CC "&_ "WHERE TC.topcategoryID = CC.topcategorylink "&_ "AND MC.tbmiddlecategoryID = CC.middlecategorylink " &_ "GROUP BY TC.topcategory "
And now your thing should work.
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
NO NO, you have to keep GROUP BY clause in there, if you don't, your records won't go in the right places, and you'll have duplicate columns!
You just need to lose the DISTINCT. DISTINCT grabs only the unique ones. So if you have 10 TopCats named NameMyTopCat, it will only pull 1. Since it only pulls 1, it will only pull one MiddleCat. That's where you failed.
You just need to lose the DISTINCT. DISTINCT grabs only the unique ones. So if you have 10 TopCats named NameMyTopCat, it will only pull 1. Since it only pulls 1, it will only pull one MiddleCat. That's where you failed.
•
•
Join Date: Feb 2008
Posts: 174
Reputation:
Solved Threads: 3
Yes this was the right one, added middlecat as well to GROUP BY and it is working
SQL = "SELECT TC.topcategory, MC.middlecategory "&_
"FROM tbtopcategory TC, tbmiddlecategory MC, tbconnectcategory CC "&_
"WHERE TC.topcategoryID = CC.topcategorylink "&_
"AND MC.tbmiddlecategoryID = CC.middlecategorylink " &_
"GROUP BY TC.topcategory ASC, MC.middlecategory ASC"
set RS = Server.CreateObject("ADODB.recordset")
SQL = "SELECT TC.topcategory, MC.middlecategory "&_
"FROM tbtopcategory TC, tbmiddlecategory MC, tbconnectcategory CC "&_
"WHERE TC.topcategoryID = CC.topcategorylink "&_
"AND MC.tbmiddlecategoryID = CC.middlecategorylink " &_
"GROUP BY TC.topcategory ASC, MC.middlecategory ASC"
set RS = Server.CreateObject("ADODB.recordset")
•
•
Join Date: Sep 2007
Posts: 1,080
Reputation:
Solved Threads: 68
You probably don't even need middlecategory. If you wish, you should do it this way:
This way it will grab only the unique sub names (which you don't want duplicates of anyway). No need for group by, as when you have uniques, grouping 1, 2, 3 will turn out as 1, 2, 3. It's pointless.
Glad to see its working. Show me?
ASP Syntax (Toggle Plain Text)
SQL = "SELECT TC.topcategory, DISTINCT(MC.middlecategory) "&_ "FROM tbtopcategory TC, tbmiddlecategory MC, tbconnectcategory CC "&_ "WHERE TC.topcategoryID = CC.topcategorylink "&_ "AND MC.tbmiddlecategoryID = CC.middlecategorylink " &_ "GROUP BY TC.topcategory"
This way it will grab only the unique sub names (which you don't want duplicates of anyway). No need for group by, as when you have uniques, grouping 1, 2, 3 will turn out as 1, 2, 3. It's pointless.
Glad to see its working. Show me?
•
•
Join Date: Feb 2008
Posts: 174
Reputation:
Solved Threads: 3
This is the output (before I prints it out and hang it in some golden frame)
•
•
•
•
You probably don't even need middlecategory. If you wish, you should do it this way:
ASP Syntax (Toggle Plain Text)
SQL = "SELECT TC.topcategory, DISTINCT(MC.middlecategory) "&_ "FROM tbtopcategory TC, tbmiddlecategory MC, tbconnectcategory CC "&_ "WHERE TC.topcategoryID = CC.topcategorylink "&_ "AND MC.tbmiddlecategoryID = CC.middlecategorylink " &_ "GROUP BY TC.topcategory"
This way it will grab only the unique sub names (which you don't want duplicates of anyway). No need for group by, as when you have uniques, grouping 1, 2, 3 will turn out as 1, 2, 3. It's pointless.
Glad to see its working. Show me?
![]() |
Similar Threads
- Do/While Loop help (C++)
- nested for loop problem (Java)
- Can not enter multiple data into nested while loop (C++)
- problem creating a for loop for an array (C++)
- Nested loop that runs until user enters 'q' (C++)
- QBasic Nested for loop (Legacy and Other Languages)
- need help w/for loop (C++)
Other Threads in the ASP Forum
- Previous Thread: Help: passing variable via table field different page subroutine
- Next Thread: Convert Int to string classic asp
| Thread Tools | Search this Thread |
archive asp asp.net aspandmssqlserver2005 aspandmssqlserver2005connection aspconnection calendar changeable connection current database databaseconnection diagnostics dreamweaver excel fso html iis microsoft msmsql mssql2005 mssqlserver2005 mssqlserver2005andasp mssqlserverandasp opentextfile record searchbox selectoption server single specfic sqlserver sqlserverconnection toolkit web webserver windows7






