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 8857055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:30:02+00:00 2026-06-14T14:30:02+00:00

I am trying to run a query that for a selected person, it will

  • 0

I am trying to run a query that for a selected person, it will recommend items based on their purchase history and what other people have bought who also bought that item.

Example:

Customer 1 purchases item A, and B.
Customer 2 purchases item B. 
Customer 2 is recommended, item A.  

I have 4 tables that are used in this I will list them with the relevant row names.

Customer
PK: Cust_ID

Session
PK: Ses_ID
FK: Cust_ID

Order
PK: Order_ID
FK: ItemRef_ID
FK: Session_ID

Item
PK: Item_ID

I’m pretty new to SQL but here’s what I’ve got so far, following that I really have no idea how to go about doing it.

Currently it only gives the items that the selected customer has bought ‘Lani Morgan’, but instead I’d like it to display items that other customers have bought, who have bought the item ‘Lani Morgan’ has bought.

SELECT Item_Desc, Item_ID 
FROM  rbickers.Item

LEFT JOIN rbickers.Order 
ON Item.Item_id = Order.itemref_id 

LEFT join rbickers.Session 
ON Order.Session_id = Session.Ses_id 

left join rbickers.customer
On customer.cust_ID = session.Cust_ID

Where Cust_First = "Lani" and Cust_Last = "Morgan"

GROUP BY Item_Type

LIMIT 10 

Any help would really be appreciated, thanks.

  • 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-06-14T14:30:03+00:00Added an answer on June 14, 2026 at 2:30 pm

    So by your basic version and with the supplied schema, the way I see it implemented is by checking for every item, if not bought by customer1, but bought by any other customer buying items customer1 has bought.
    Since this schema requires you to join through all of the given tables, I’d ask you to create a view of the join you’ve provided:

    create view CustomerItems as 
    SELECT *
    FROM  rbickers.Item
    
    LEFT JOIN rbickers.Order 
    ON Item.Item_id = Order.itemref_id 
    
    LEFT join rbickers.Session 
    ON Order.Session_id = Session.Ses_id 
    
    left join rbickers.customer
    On customer.cust_ID = session.Cust_ID
    
    #Where Cust_First = "Lani" and Cust_Last = "Morgan"
    

    and then:

    select distinct item.* from item, CustomerItems cust1 where 
    cust1.Cust_First="Lani" and cust1.Cust_Last="Morgan" and 
    item.Item_ID not in(
    select Item_ID from CustomerItems cust2 where cust1.Cust_ID=cust2.Cust_ID) 
    and exists(select * from CustomerItems cust3 where 
    cust3.Cust_ID<>cust1.cust_ID and item.Item_ID=cust3.Item_ID);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to run a query that will pick up days from here
So I am trying to run a query that will select, in this case,
I am trying to run a select query that will pull all meds scheduled
I am trying to run a query that selects values from a table using
I am trying to run a query that is and of two independent queries
I'm trying to figure out how to run a query that would go something
I'm trying to run a query that checks if some conditions are true and
I'm getting this error when trying to run a query that inserts results into
I'm trying to run a LINQ to SQL query that returns a result in
I have a MySQL query that I'm trying to run in SQLite. I found

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.