Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7658695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:14:07+00:00 2026-05-31T13:14:07+00:00

I’m working on developing a web portal for a bookstore, and I want to

  • 0

I’m working on developing a web portal for a bookstore, and I want to have the ability to suggest books to a user.

I want something similar to amazon.com, when a user orders book A, the system should provide a list of other suggested books. Book B is suggested if there exists a user Bob that bought both A and B. Additionally, I want my system to return the suggested books sorted on decreasing sales count, and only count sales to users that have bought both books (like Bob).

Here are the important tables:

Book(ISBN, title, publicationYear, etc..)

Orders(orderID, loginName, date)

BooksOrdered(orderID, ISBN, count)

This query is more complex than anything I’ve previously tried.

Current thoughts:

First find all the users that have ordered the same book (ISBN)

  1. Join all three tables on Book.ISBN = BooksOrdered.ISBN AND Orders.orderID = BooksOrdered.ISBN
  2. WHERE Book.ISBN = bookInQuestionISBN
  3. GROUP BY Orders.loginName
  4. Project out loginName

So something like:

SELECT Orders.loginName as otherBuyerLoginName
FROM Book, Orders, BooksOrdered,
WHERE Book.ISBN = bookInQuestionISBN AND Orders.orderID = BooksOrdered.ISBN
GROUP BY Orders.loginName

Then I could grab all the books these loginNames have ordered, group them by loginName, sum count and ORDER BY DESC SUM(BooksOrdered.count).

However, I’m thinking that the first result will most likely be the book in question. I don’t want to suggest the same book the user has just bought.

What do you suggest? Maybe I should start over from scratch?

EDIT:

Here is some data:

BooksOrdered contains:

orderID ISBN        count
    3   FakeISBN    3
    7   FakeISBN    3
    8   FakeISBN    100
    11  FakeISBN2   40
    7   FakeISBN2   4
    10  FakeISBN2   20
    10  FakeISBN3   34
    11  TesterISBN  3
    9   TesterISBN  1

Orders contains:

orderID loginName  date
2       Tester     2012-03-15 19:43:27
3       Tester     2012-03-16 15:56:55
6       Tester2    2012-03-16 17:28:02
7       Tester     2012-03-16 17:31:21
8       ni3hao3    2012-03-16 23:18:15
9       ni3hao3    2012-03-17 13:12:38
10      ni3hao3    2012-03-17 13:13:55
11      Bobby      2012-03-17 13:28:14

Alright, now I want to know the top suggestions for the book with ISBN = “TesterISBN”

Two people have ordered “TesterISBN”: ni3hao3 and Bobby

ni3hao3’s total sales history:

1 copy of "TesterISBN"
100 copies of "FakeISBN"
20 copies of "FakeISBN2"
34 copies of "FakeISBN3"

Bobby’s total sales history:

3 copies of "TesterISBN"
40 copies of "FakeISBN2"

So the totals of sales for purchasers of “TesterISBN” are as follows:

4 copies of "TesterISBN"
100 copies of "FakeISBN"
60 copies of "FakeISBN2"
34 copies of "FakeISBN3"

So I’d like the results to return:

FakeISBN
FakeISBN2
FakeISBN3

In that order.

EDIT:

I believe I’ve figured it out:

SELECT Bo.ISBN, B.title, SUM(Bo.count) 
FROM BooksOrdered Bo, Orders O, Book B
WHERE Bo.orderID = O.orderID AND Bo.ISBN = B.ISBN
                            AND Bo.ISBN != 'TesterISBN'
                            AND O.loginName IN ( SELECT DISTINCT(Orders.loginName) as otherBuyerLoginName
                            FROM Orders, BooksOrdered
                            WHERE BooksOrdered.ISBN = 'TesterISBN' 
                                AND Orders.orderID = BooksOrdered.orderID)
GROUP BY Bo.ISBN
ORDER BY SUM(Bo.count) DESC
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:14:08+00:00Added an answer on May 31, 2026 at 1:14 pm
    SELECT Bo.ISBN, B.title, SUM(Bo.count) 
    FROM BooksOrdered Bo, Orders O, Book B
    WHERE Bo.orderID = O.orderID AND Bo.ISBN = B.ISBN
                                AND Bo.ISBN != 'TesterISBN'
                                AND O.loginName IN ( SELECT DISTINCT(Orders.loginName) as otherBuyerLoginName
                                FROM Orders, BooksOrdered
                                WHERE BooksOrdered.ISBN = 'TesterISBN' 
                                    AND Orders.orderID = BooksOrdered.orderID)
    GROUP BY Bo.ISBN
    ORDER BY SUM(Bo.count) DESC
    

    This seems to do the trick

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.