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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:25:28+00:00 2026-05-14T19:25:28+00:00

I have two tables that were built for two disparate systems. I have records

  • 0

I have two tables that were built for two disparate systems. I have records in one table (called “leads”) that represent customers, and records in another table (called “manager”) that are the exact same customers but “manager” uses different fields

(For example, “leads” contains an email address, and “manager” contains two fields for two different emails–either of which might be the email from “leads”).

So, I’ve created a correlation table that contains the lead_id and manager_id. currently this correlation table is empty.

I’m trying to query the “leads” table to give me records that match either “manager” email field with the single “leads” email field, while at the same time ignoring fields that have already been added to the “correlated” table. (this way I can see how many leads that match have not yet been correlated.) Here’s my current, invalid SQL attempt:

SELECT leads.id, manager.id
  FROM leads, manager
  LEFT OUTER JOIN correlation ON correlation.lead_id = leads.id
  WHERE correlation.id IS NULL
  AND leads.project != "someproject"
  AND (manager.orig_email = leads.email OR manager.dest_email = leads.email)
  AND leads.created BETWEEN '1999-01-01 00:00:00' AND '2010-05-10 23:59:59'
  ORDER BY leads.created ASC;

I get the error: Unknown column ‘leads.id’ in ‘on clause’

Before you wonder: there are records in the “leads” table where leads.project != “someproject” and leads.created falls between those dates. I’ve included those additional parameters for completeness.

  • 1 1 Answer
  • 3 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-14T19:25:29+00:00Added an answer on May 14, 2026 at 7:25 pm

    You have the tables listed the wrong way round so the LEFT OUTER JOIN is joining manager to correlation instead of leads to correlation as you intended. Try swapping them round:

    SELECT leads.id, manager.id
      FROM manager, leads
      LEFT OUTER JOIN correlation ON correlation.lead_id = leads.id
      WHERE correlation.id IS NULL
      AND leads.project != "someproject"
      AND (manager.orig_email = leads.email OR manager.dest_email = leads.email)
      AND leads.created BETWEEN '1999-01-01 00:00:00' AND '2010-05-10 23:59:59'
      ORDER BY leads.created ASC;
    

    In general I’d recommend not mixing old and new style joins to avoid exactly this type of error. I’d prefer to see something like this:

    SELECT leads.id, manager.id
      FROM leads
      LEFT OUTER JOIN correlation ON correlation.lead_id = leads.id
      JOIN manager ON manager.orig_email = leads.email OR manager.dest_email = leads.email
      WHERE correlation.id IS NULL
      AND leads.project != "someproject"
      AND leads.created BETWEEN '1999-01-01 00:00:00' AND '2010-05-10 23:59:59'
      ORDER BY leads.created ASC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables that I'm querying from. In one table, there are fields
I have two tables that link together through an id one is submit_moderate and
I have two tables that are related via a mapping table: keywords titles I
Suppose I have two tables that are linked (one has a foreign key to
I have a table, say STUDENTS, that is related one-to-many to another table, CLASSES.
So I have two tables that have a layout like (but not named): Table
I have two tables that have a one-to-many relationship table1 (one), table2 (many). table1
I have two tables that have virtually identical content and very similar structure. They
I have two tables that I want to join together. Table1 Year, ID, Theme,
I have two tables that should be joined together by a foreign key relationship,

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.