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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:46:05+00:00 2026-06-17T11:46:05+00:00

I am relatively new to programming and databases. I have a MySQL database with

  • 0

I am relatively new to programming and databases.

I have a MySQL database with a “sales” table. This table lists all sales in a state (i.e. each record is a particular sale), with fields for sellername, and buyerzip. I would like to have another table “seller” that would include sellername, and also include fields to define the sellers market area by zip code – say 50+ zip codes define a market, and the seller could define multiple markets.

These market areas would be used for future queries: showing all sales in a particular market area.

Where do I start in terms of thinking how to store that “market area” data, and then use it for future queries?

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-17T11:46:06+00:00Added an answer on June 17, 2026 at 11:46 am

    Table structure:

    • Sales table: ID, sellerID, buyerZipcode, amount
    • Seller table: ID, sellerName
    • Market table: ID, marketName
    • SellerMarketLink table: ID, sellerID, marketID
    • MarketZipCode table: ID, marketID, zipCode

    Example data

    Encoding the information in the first comment to your question

    Market table

    1, “Store A, first market”
    2, “Store A, second market”
    3, “Store B market”

    MarketZipCode table

    1, 1, 1
    2, 1, 2
    …
    7, 1, 7
    8, 1, 8
    9, 2, 4
    10, 2, 5
    …
    14, 2, 9
    15, 2, 10
    16, 3, 1
    17, 3, 2
    18, 3, 3
    19, 3, 8
    20, 3, 9
    21, 3, 10
    22, 3, 11
    23, 3, 12

    Query

    Total sales in a market for each seller. Note that since one zip code can be part of several markets, the total of all values in “Total Sales” can be larger than the sum of all ‘amount’ values in the Sales table.

    select Market.marketName, Seller.sellerName, sum(Sales.amount) as "Total Sales"
    from Sales join Seller join SellerMarketLink join Market join MarketZipCode
    on (Sales.sellerID = Seller.ID AND Seller.ID = SellerMarketLink.sellerID 
      AND SellerMarketLink.marketID = Market.ID 
      AND Market.ID = MarketZipCode.marketID 
      AND MarketZipCode.zipCode = Sales.buyerZipCode)
    group by Market.ID, Market.marketName, Seller.ID, Seller.sellerName
    order by Market.marketName, Seller.sellerName
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really need your help for this. I am relatively new to programming and
I am relatively new to Objective-C / iPhone programming, and have only created single
I am relatively new to Android programming, but have had experience in Java and
I'm relatively new to iPhone programming but have read my way through a hefty
I am relatively new to socket programming so this may sound like a very
I am relatively new to programming for Androids and I have a back ground
I'm relatively new to programming and am new to this site, please bear with
I am very new to Java, and relatively new to programming. I have 3
Ok I am relatively new to Java Programming, but have previous experience in C++.
I am relatively new to programming, as you will soon see... I have 2

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.