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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:55:07+00:00 2026-06-13T22:55:07+00:00

I have a table col1 1 2 and other table col1 col2 col3 1

  • 0

I have a table

col1

1
2

and other table

col1    col2    col3

1          1    data value one                                    
1          2    data value one                                    
2          3    data value two   

and I want to join both tables to obtain the following result

col1  col2  col3

1       1    data value one
2       3    data value two

The second table have duplicates but I need to join only one (randomly). I’ve tried with Inner Join, Left Join, Right Join and always returns all rows. Actually I use SQL Server 2008.

  • 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-13T22:55:08+00:00Added an answer on June 13, 2026 at 10:55 pm

    You can use the ROW_NUMBER Function along with ORDER BY NEWID() To get one random row for each value in col1:

    WITH CTE AS
    (   SELECT  Col1,
                Col2,
                Col3, 
                [RowNumber] = ROW_NUMBER() OVER(PARTITION BY Col1 ORDER BY NEWID())
        FROM    Table2
    )
    SELECT  *
    FROM    Table1
            INNER JOIN CTE
                ON CTE.Col1 = table1.Col1
                AND CTE.RowNumber = 1 -- ONLY GET ONE ROW FOR EACH VALUE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: A (col1,col2,col3,col4) B (col1,col2,col3,col4) Table A has 4 records(rows) and
I have two tables as below: Student: oneID (primary key), col1, col2, col3, subId,
I have a table like Table1: col1 col2 col3 and have an index over
I have a table like below: COL1 | COL2 | COL3 ______________________ ITEM1 |
I have a table with columns say col1, col2, col3 . The table has
I have a table with four Columns: Col1, Col2, Col3, and Col4. Col1, Col2,
MY base table have two colums assume col1,col2. col1 have id, col2 have many
I have a table, for example, mytable. It has several columns: col1, col2, col3.
I have two very large enterprise tables in an Oracle 10g database. One table
So I have two tables. Table1 have two columns, col1 and col2, where col1

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.