Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Tough SQL Query Problem
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Tough SQL Query Problem

 Post Reply Post Reply
Author
erika1959 View Drop Down
Newbie
Newbie


Joined: 07 November 2004
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote erika1959 Quote  Post ReplyReply Direct Link To This Post Topic: Tough SQL Query Problem
    Posted: 07 November 2004 at 5:16am

I've just started learning SQL in order to manipulate my databases, but the gargantuan nature of the following problem has obscured my ability to think striaght, so that I don't really have any clear idea about what kind of query I need to write in order to solve it!


I have 2 tables;
- sts-catalogue, which is a catalogue of products.  It has fields as follows;

Product Number
Product Name
Price
Short Description
Category 1
Category 2
Category 3
Picture
Add to Cart Link
Thumbnail
.


- ratings-review, which is a database of user ratings and reviews for those products. Its fields are;

Product Number
Rating
Rating Link
Star Rating
Comments


I want to join/merge these two tables.  However there are a couple of complications;


- Not every product listed in sts-catalogue has a corresponding record in ratings-review (although all records in ratings-review are present in sts-catalogue).

- With the table ratings-review, there are many occurences of more than one user review for a single product, so that the same Product Number and Rating Link appears in several records, even though the Rating,Star Rating and Comments fields for each record is different.


Because I want to produce web pages individual products, which will include all the reviews for a particular product appearing on the same page, I'm going to need to have individual records which will include a field for each series of ratings.


Thus my final joined table format will need to look something like this:


Product Number
Product Name
Price
Short Description
Category 1
Category
Category 3
Picture
Add to Cart Link
Thumbnail
Rating Link
Rating1
Star Rating1
Comments1
Rating2
Star Rating2
Comments2
Rating3
Star Rating3
Comments3(...and so on)
 
 

It might appear that I'm simply getting someone to do my dirty work for me here, but I'm not being lazy - I tend to take solutions and play with them in different situations, which expands my ability to think for myself, so any help offered will be greatly appreciated.

Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 07 November 2004 at 10:29am
You're not going to be able to do that. You can product additional ROWS with the ratings comments, but not additional COLUMNS.

Do a JOINon the two tables and then move through the record set to display all the reviews.


If you are using MS SQL Server, then my suggestion would be to use a stored procedure and return one record with the product info and one recordset with the ratings information.
Back to Top
MadDog View Drop Down
Mod Builder Group
Mod Builder Group
Avatar

Joined: 01 January 2002
Status: Offline
Points: 3008
Post Options Post Options   Thanks (0) Thanks(0)   Quote MadDog Quote  Post ReplyReply Direct Link To This Post Posted: 07 November 2004 at 12:05pm

This will join the tables together even if the rattings table is empty:

SELECT sts-catalogue.* FROM sts-catalogue LEFT JOIN ratings-review ON sts-catalogue.product_number =  ratings-review.product_number;

*UNTESTED*

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.