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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:50:12+00:00 2026-06-04T10:50:12+00:00

I have 2 tables… table1 and table2. I want to display all serial numbers

  • 0

I have 2 tables… table1 and table2.

I want to display all serial numbers from table1

table2 has also has serial numbers in it

I would like to compare the serial numbers in table1 with table2

I would then like to display all the serial numbers in table1 and have a second column with a yes if the serial number was in table1 or a no if it wasn’t

Is this possible to do with a sql statement or do I have to build a seperate table? i’m running sql-server.

  • 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-04T10:50:13+00:00Added an answer on June 4, 2026 at 10:50 am

    If serial numbers in each table are unique then you could use:

    SELECT  Table1.SerialNumber,
            CASE WHEN Table2.SerialNumber IS NULL THEN 'No' ELSE 'Yes' END AS [IsInTable2]
    FROM    Table1.SerialNumber
            LEFT JOIN Table2
                ON Table2.SerialNumber = Table1.SerialNumber
    

    If there are Duplicates in one or both tables then either of the following will work:

    SELECT  DISTINCT 
            Table1.SerialNumber,
            COALESCE([IsInTable2], 'No') [IsInTable2]
    FROM    Table1.SerialNumber
            OUTER APPLY
            (   SELECT  TOP 1 'Yes' [IsInTable2]
                FROM    Table2
                WHERE   Table2.SerialNumber = Table1.SerialNumber
            ) Table2
    
    
    SELECT  DISTINCT
            Table1.SerialNumber,
            CASE WHEN Table2.SerialNumber IS NULL THEN 'No' ELSE 'Yes' END [IsInTable2]
    FROM    Table1.SerialNumber
            LEFT JOIN 
            (   SELECT  DISTINCT SerialNumber
                FROM    Table2
            ) Table2
                ON Table2.SerialNumber = Table1.SerialNumber
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tables like this: Table1 Table2 name1 | link_id name2 | link_id text
The dataset have tables and columns details got from the XML file.I want to
I have tables like these two test_table date student test 2012-05-31 Alice Math 2012-05-31
I have tables like this: tblUsers int UserID string UserName tblUsersInRoles int UserID int
I used to have tables before to display the content and people here advised
hi i have tables like this: Persons: person_id, name then i have many langauge
I have tables named: Posts_August_2011 Posts_September_2011 Posts_October_2011 Posts_November_2011 Posts_December_2011 Posts_January_2012 I want to create
I have tables like: 'profile_values' userID | fid | value -------+---------+------- 1 | 3
I have tables, 1 called articles and another called links. I want to take
Hi i have tables like this : table entry : id | total_comments _____________________

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.