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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:30:28+00:00 2026-06-19T04:30:28+00:00

I want to return all the postcodes in table1 that are active and that

  • 0

I want to return all the postcodes in table1 that are active and that dont have any items in table2 that share the same coordinates (lat,lng).
I.e. in the below return :

AB11AC

I know there are several method where you are just checking one column, but not sure how to adapt for 2 columns. Should I just concatenate the 2 columns together in the query or is there a more efficient method? My tables each have around 2 million entries.

table1:

postcode  lat  lng active
-------------------------
AB11AA   55   1    Y
AB11AB   56   1    Y
AB11AC   57   1    Y

table2:

postcode  lat  lng active
--------------------------
AB11AA   55   1   Y
AB11AD   56   1   Y
AB11AE   59   1   Y
  • 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-19T04:30:30+00:00Added an answer on June 19, 2026 at 4:30 am

    You can use a LEFT JOIN:

    select *
    from table1 t1
    left join table2 t2
      on t1.lat = t2.lat
      and t1.lng = t2.lng
    where t1.active = 'Y'
      and t2.postcode is null
    

    See SQL Fiddle with Demo

    Or you can use a NOT EXISTS in the WHERE clause:

    select *
    from table1 t1
    where t1.active = 'Y'
      and not exists (select *
                      from table2 t2
                      where t1.lat = t2.lat
                        and t1.lng = t2.lng)
    

    See SQL Fiddle with Demo

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

Sidebar

Related Questions

The scenario: Table1 CatId|Name|Description Table2 ItId|Title|Date|CatId (foreign key) I want to return all rows
I have a table DriverScans that joins DriverImages. I want to return all DriverScans
I have a query where I want to return all Clients that have a
I have 2 tables: POHeader and PODetail. I want to return all POHeaders that
All I want to do is return the index of the i that is
I have the following classes below, I want to return all USLocation classes for
I have a select statement and want to return all values only if at
I have two index arrays and I want to return all the indices in
I want to return all records that were added to the database within the
I have a simple SqlCommand in which I want to return all records within

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.