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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:48:53+00:00 2026-06-12T21:48:53+00:00

Here is the schema of the database I’m working with – [redacted] I’m trying

  • 0

Here is the schema of the database I’m working with – [redacted]

I’m trying to come up with 2 different queries for 2 different result sets –

  1. Sales representatives with the highest sales
  2. Sales representatives with the highest sales grouped by managerId

I’ve had some luck with the 1st query; this is what I came up with:

SELECT
    SUM(`products`.`cost`) AS `Sale`
    , `employees`.`firstName`
FROM
    `d2dpro`.`sales_reps`
    , `d2dpro`.`products`
    INNER JOIN `d2dpro`.`employees` 
        ON (`sales_reps`.`employeeId` = `employees`.`employeeId`)
    INNER JOIN `d2dpro`.`sold_products` 
        ON (`products`.`productId` = `sold_products`.`productId`)
    INNER JOIN `d2dpro`.`sales` 
        ON (`sold_products`.`saleId` = `sales`.`saleId`) AND (`sales`.`salesCampId` = `sales_reps`.`saleCampId`)
GROUP BY `employees`.`firstName`;

With this query, I’m stuck with this error:
Error Code: 1054
Unknown column 'sales_reps.saleCampId' in 'on clause'

Any help with this query? And also for the 2nd one?

  • 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-12T21:48:54+00:00Added an answer on June 12, 2026 at 9:48 pm

    You are using one table (sales_reps) that is CROSS JOIN-ed with the INNER JOIN of the tables employees, sold_products and sales. To be able to reference sales_reps in that JOIN you should include it as inner join: (the FROM clause should look like this)

    FROM `d2dpro`.`products`
        INNER JOIN `d2dpro`.`employees` 
            ON (`sales_reps`.`employeeId` = `employees`.`employeeId`)
        INNER JOIN `d2dpro`.`sold_products` 
            ON (`products`.`productId` = `sold_products`.`productId`)
        INNER JOIN `d2dpro`.`sales` 
            ON (`sold_products`.`saleId` = `sales`.`saleId`)
        INNER JOIN `d2dpro`.`sales_reps` 
            ON (`sales`.`salesCampId` = `sales_reps`.`saleCampId`)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just getting into SQL stored queries right now... anyway, here's my database schema (simplified
Here is my Database schema and the tables I am trying to link, I
The Media Wiki database Schema, here , has taught me a lot. Cannot-understand: In
Here is my current setup: Database Role - MyDbRole Schema - MySchema User -
I have the following database schema: Here's how I populate a DropDownList in my
I am trying to map a new domain model to a fixed-schema legacy database
here's a more general question on how you handle database schema changes in a
Here is the most relevant part of my database schema: create table TEST (
I am trying to design an efficient database schema for user settings in SQL
Please guide me if I'm on right track. I'm trying to create database schema

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.