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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:21:47+00:00 2026-05-20T21:21:47+00:00

Suppose the records in database are as below: Id FirstName LastName OrderPrice 1 Tom

  • 0

Suppose the records in database are as below:

Id         FirstName       LastName        OrderPrice
1          Tom             Hanks           123
2          Tom             Hanks           173
3          Tom             Hanks           123
4          Tom             Bob             123
5          Robert          Hanks           123

Given Input : Id = 1
Expected OUtput : Id = 3

I know that I can write some thing like below

Declare @Id as INT = 1
Declare @FirstName as varchar(100)
Declare @LastName as varchar(100)
Declare @OrderPrice as INT

Select @FirstName = FirstName, @LastName  = LastName , @OrderPrice = OrderPrice  From Customers Where Id= @ID

Select ID From Customers Where FirstName = @FirstName and LastName = @LastName and OrderPrice = @OrderPrice

But, I do not want to write some thing like where I should mention all the columns names in where condition. Because actually the record I was working on contains almost 100 columns in it. So, I was asked not to use a query some thing like this.

Can any one help me how to do this?

  • 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-20T21:21:48+00:00Added an answer on May 20, 2026 at 9:21 pm

    You can use dynamic SQL to create a query to search for duplicate records. Basically, this query builds a string like a.col1 = b.col1 and a.col2 = b.col2 and ... and uses that as the on clause in a self-join:

    declare @columns varchar(max)
    
    select  @columns = 
                case when @columns is null then 'a.' else @columns + ' and a.' end +
                quotename(name) + ' = b.' + quotename(name)
    from    sys.columns
    where   object_id = object_id('YourTable')
            and name <> 'ID'
    
    declare @query varchar(max)
    set @query = 'select b.ID from YourTable a ' +
        'join YourTable b on a.ID <> b.ID and ' + @columns + ' where a.ID = 1'
    exec (@query)
    

    This searches for rows that duplicate ID = 1, except for the ID.

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

Sidebar

Related Questions

Suppose i have 1kk records in my database. Now i need to select some
I have like 400 records on my database, suppose this is the first version
Suppose that I have a database query which looks like below - select name,
Suppose I have a database containing 500,000 records, each representing, say, an animal. What
suppose i have 10,000 records in database but i want to show 100 record
Let's suppose I have a table in my database with 1.000.000 records. If I
suppose i am having a database table with 20 records and of that i
Suppose, you have a larger database of customers, such as 5000 records. Using a
i'm wondering how am i suppose to update my database data of different records
Suppose you want to get a record from database which returns a large amount

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.