Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 31st, 2005, 02:24 AM
Registered User
 
Join Date: Oct 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default My SQL, ASP, and Inner Join

Hello All,

I have a bit of a problem I can't seem to figure out. I have a My SQL database with three tables (Items, Item Catagory, and Item Sizes). If someone wants to see a item category of Pizza I need to have all Items that are linked to Pizza to show but I also need to have all Pizza sizes to show in columns. For example: If you click on the pizza catagory I need to to return results such as:

-------------------------------------
Item |Sm | Med | Lg | Super
-------------------------------------
Plain Pie |$5 | $7 | $9 | $11
Meatball Pie|$6 | $8 | $11| $13
and so on...

But when I use inner join I get multiple records for Sizes. I am using the following SQL command:

SELECT items.ID, items.Catagory1ID, items.Name as Item, items.Description as Description, item_sizes.Name as ItemSize, item_sizes.Description as ItemDescription, item_sizes.Default, item_sizes.Cost

FROM items

INNER JOIN item_sizes

ON items.Catagory1ID = item_sizes.itemID

WHERE items.Catagory1ID = 1 ORDER BY items.item

Now it will return a total of 8 records a record for each size and the same pizza type but there are only two Pizza types (Plain and Meatball) and 4 sizes for each pizza. How can I code this out so it will only show the Pizza found from Items and show the pizza sizes available from Item Sizes table?

Here all my code that I have tried:

RecordSet.Open "SELECT items.ID, items.Catagory1ID, items.Name as Item, items.Description as Description, item_sizes.Name as ItemSize, item_sizes.Description as ItemDescription, item_sizes.Default, item_sizes.Cost FROM items INNER JOIN item_sizes ON items.Catagory1ID = item_sizes.itemID WHERE items.Catagory1ID = 1 ORDER BY items.item"

<table width="100%" border="0" cellspacing="0" cellpadding="0"> Response.Write "<tr>" 'Create a row
    Response.Write "<td></td>" Leave this column blank.


'The following code will create a table and add columns per each item size titles records it finds in Item Sizes.
For I = 1 TO RecordSet.RecordCount / 2
Response.Write "<td>" & RecordSet("ItemSize") & "</td>" 'Create a column

RecordSet.MoveNext

Next

Response.Write "</tr>" 'Close the row
RecordSet.MoveFirst

'The following will the show the Pizza's found in Items tables in the first Column.
Do While NOT RecordSet.EOF = True

Response.Write "<tr>" 'Create the first row and show the Pizza name.
Response.Write "<td>" & RecordSet("Item") & "</td>"


Do While NOT RecordSet.EOF = True

'Show the cost in the next column right under the size title
Response.Write "<td>" & FormatCurrency(RecordSet("Cost"), 2) & "</td>" 'Create a column with prices for sizes
                                        RecordSet.MoveNext 'Move to next record
                                        Loop

    Response.Write "</tr>" 'Close the row

Loop

But this isn't working the way I would like. Becuase of the 8 records it loops 8 times and repeats the sizes on the top column titles and only shows one pizza type rather than two. Can someone please help me figure out how to manage multiple records with inner join and showing it like the example above. Thank you!

Frank







Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help using join in SQL query yogeshyl SQL Language 1 July 30th, 2008 04:12 AM
SQL INNER JOIN problem lawsoncobol Access VBA 1 August 17th, 2006 02:29 PM
SQL join problem mattastic SQL Language 2 May 26th, 2005 08:27 AM
SQL Join mattastic SQL Server 2000 9 April 21st, 2005 10:27 AM
SQL Inner Join Problem tp194 Classic ASP Databases 2 July 8th, 2003 09:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.