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

  • Home
  • SEARCH
  • 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 6037835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:07:54+00:00 2026-05-23T06:07:54+00:00

SQL is my weak part, however I can handle it. I was wondering if

  • 0

SQL is my “weak” part, however I can handle it. I was wondering if there are better ways of writing my queries below. Any alternative like small tweaks or editing is welcome, it’s a way for me to learn more.

I have the expected/correct results on all of them.

Shows which shops have the product code 1234 giving the code, name and address of them.

SELECT k.ShopCode, Name, Address FROM shops as k
INNER JOIN availability as d ON k.ShopCode=d.ShopCode
WHERE d.ProductCode = '1234';

Shows the average value of transactions in the shop with code 2, including the name, address and the average price of transactions.

SELECT Name, Address, AVG(QUANTITY*ProductPrice) AS AveragePrice
FROM shop AS k
INNER JOIN chashier AS t ON k.ShopCode = t.ShopCode
INNER JOIN buy AS a ON t.CashierCode = a.CashierCode
INNER JOIN contains AS p ON a.BuyCode = p.BuyCode
WHERE t.ShopCode = '1'
GROUP BY NAME, ADDRESS

Shwos the name, address and the amount of the top three in total purchasing customers of the chain.

SELECT TOP 3 BuyerName, BuyerSurname, Address, SUM(QUANTITY*ProductPrice) AS AveragePrice
FROM buyer AS pe
INNER JOIN buy AS a ON pe.CardCode = a.BuyerCode
INNER JOIN contains AS p ON a.BuyCode= p.BuyCode
GROUP BY pe.CardCode, BuyerName, BuyerSurname, Address
ORDER BY AveragePrice DESC;

This one shows the new products that not yet launched in the shops and therefore
not participate in any buy. The answer includes the code and description of the product.

SELECT BuyCode, description from products
WHERE product.BuyCode not in
( select distinct store_has_products.product_id FROM store_has_products)

It shows the manager of each shop. The answer includew the store code and the name of the manager.

SELECT works.store_id as, employee.first_name, employee.last_name FROM manager
left join employee on manager.id = employee.id
lefti join works on employee.id = works. employee_id
  • 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-23T06:07:55+00:00Added an answer on May 23, 2026 at 6:07 am

    I’d change the 4th query (products that have no launched yet) to use EXISTS…

    SELECT BuyCode, description FROM products
    WHERE NOT EXISTS (SELECT * FROM store_has_products WHERE product_id = products.BuyCode)
    

    (I’ve seen very poor performance from using IN over large sets. That may have improved, I’ve not used MySQL in ages. But this is at least an alternative formulation.)

    The rest look fine to me…

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

Sidebar

Related Questions

SQL novice here. I'm trying to get a list of invoice numbers. There are
I am weak in SQL and need some help working through some logic with
My SQL-fu is too weak for this, and I'm not even sure it's possible
my foundation on SQL is pretty weak so I hope you could bear with
SQL queries are still my weakest point, so here I am with yet another
SQL Server Management Studio: Is there a way to execute current row (keyboard shortcut)
I have a rather weak understanding of any of oracle's more advanced functionality but
SQL Experts, Is there an efficient way to group runs of data together using
We have a new SQL 2008 R2 instance that's part of a cluster (active/passive)
Sql Server is accessible. I want to migrate database using Entity Framework migrations. There

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.