SQL/ASP Group By/Select Question

Results 1 to 3 of 3

Thread: SQL/ASP Group By/Select Question

  1. #1
    Join Date
    Dec 1969

    Default SQL/ASP Group By/Select Question

    I have a SQL table with a list of links. Each URL is categorized in at least one and up to four categories. Each category is stored in a column: C1, C2, C3, and C4. The categories are stored in order of relevance.<BR><BR>I&#039;m trying to write a SELECT statement that will group URLs by category. I need URLs to be listed under each category that are in one of the four corresponding category columns.<BR><BR>Thus, even though there is only one record for each URL, I need a URL to be returned each time it falls into a certain category.<BR><BR>Can anyone help me write a select statement to do this?<BR><BR>Do I have to write four seperate statements--one for each column--and put the recordsets together? How would I put to record sets together if I did this?<BR><BR>I know that this grouping-by-column that I want to do would be easily acheived if I reorganized the table by URL so that each URL was inputed as a separate record for each category it fell under. But, for other reasons, I don&#039;t want to change this setup if I don&#039;t have to.<BR><BR>I greatly appreciate any ideas anyone has. Please let me know if I have not provided enough information.<BR><BR>Thanks,<BR>Chris

  2. #2
    Richard K Guest

    Default RE: SQL/ASP Group By/Select Question

    &#062;How would I put to record sets together if I did this?&#062;<BR>One way of doing that could be by using UNION. That gives you the chance to have multiple selects but only one recordset. Could be worth checking out...

  3. #3
    Join Date
    Dec 1969

    Default Tried the UNION, but isn't grouping

    I&#039;ve tried the UNION command, and it&#039;s returned the multiple select statements together into one recordset, but what I need is create a recordset that puts the C1, C2, C3, and C4 columns together into one column that I can order by.<BR><BR>Should I use a JOIN command instead? And, what would this statement look like?<BR><BR>Here&#039;s my SQL Statement as it is now.<BR><BR>"SELECT * FROM tblSources " & _<BR>"UNION SELECT * FROM tblSources " & _<BR>"UNION SELECT * FROM tblSources " & _<BR>" UNION SELECT * FROM tblSources"<BR><BR>Thanks for the help!<BR>Chris

Posting Permissions

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