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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:07:57+00:00 2026-06-17T15:07:57+00:00

I have a (simplified) table that is structured like so: Table: ItemData PK |

  • 0

I have a (simplified) table that is structured like so:

Table: ItemData

PK | ScanCode | StoreFK | Retail | ReceiptAlias
1  | 100101   | 1       | 4.99   | Milk
4  | 100101   | 2       | 4.99   | Milk
7  | 100101   | 3       | 0.99   | Milk
2  | 100102   | 1       | 6.99   | Eggs
5  | 100102   | 2       | 6.99   | Eggs
8  | 100102   | 3       | 6.99   | Eggs
3  | 100103   | 1       | 7.99   | Bread
6  | 100103   | 2       | 8.99   | Bread
9  | 100103   | 3       | 9.99   | Bread

I can use the following SQL query to get the following return results, which shows all the items that have a different retail at one or more stores: see this previously asked question

SQL Query:

SELECT   im.INV_ScanCode     AS ScanCode,
         name.ItemData AS im
GROUP BY ScanCode, Receipt_Alias
HAVING   COUNT(DISTINCT im.Retail) > 1
ORDER BY ScanCode

Current Return Results:

ScanCode | Receipt_Alias 
100101   | Milk
100103   | Bread

I would like to return all the items that have a different retail at one or more stores AND the retail at each store location:

Desired Return Results:

ScanCode | Receipt_Alias | Str_1 | Str_2 | Str_3
100101   | Milk          | 4.99  | 4.99  | 0.99
100103   | Bread         | 7.99  | 8.99  | 9.99

How would I change my SQL query to include the retail at each store location?

  • 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-17T15:07:59+00:00Added an answer on June 17, 2026 at 3:07 pm
    SELECT  ScanCode as ItemID,
            ReceiptAlias,
            MAX(CASE WHEN StoreFK = 1 THEN Retail ELSE NULL END) Store_1,
            MAX(CASE WHEN StoreFK = 2 THEN Retail ELSE NULL END) Store_2,
            MAX(CASE WHEN StoreFK = 3 THEN Retail ELSE NULL END) Store_3
    FROM    ItemData
    GROUP   BY ScanCode, ReceiptAlias
    HAVING  COUNT(DISTINCT Retail) > 1
    
    • SQLFiddle Demo
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a (simplified) table that is structured like so: Table: ItemData PK |
I have a table that simplified looks like this: create table Test ( ValidFrom
I have a table like this (simplified): ID | Name | Parent --------------------------------- 1
I have a table structure, simplified like so: period_id int suite_id varchar(20) suite_status varchar(50)
I have a table that reuses a foreign key and I'd like to join
My scenario is this: I have a table with a structure like this (simplified)
I have a (simplified) table consisting of three columns: id INT PRIMARY KEY NOT
I have no control over database schema and have the following (simplified) table structure:
I have the following table (simplified): user_id date hours 1 2012-03-01 5 2 2012-03-01
I have two tables with the following (simplified) structures: table "Factors" which holds data

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.