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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:05:59+00:00 2026-05-23T22:05:59+00:00

I have a database with two tables. One of the tables contains users, the

  • 0

I have a database with two tables. One of the tables contains users, the other contains addresses for those users. Each user may have several addresses (though each address is tied to only one user.)

I want to create a search that only returns one entry for each user, even if that user has several addresses. It doesn’t matter which address the search pulls back – whatever the search finds first is enough.

Here is an example search result:

tst  olix  Chicago  IL  USA
tst  olix  Los Angeles  CA  USA
tst2 olix2 Houston  TX USA

I need the search to be such that it only returns 2 rows, rather than 3.

Any ideas?

SELECT DISTINCT
    Users.Firstname, Users.Surname, Users.UserId, 
    Users.Recommendations, Addresses.City, Addresses.Region,
    Addresses.Country
FROM
    Users INNER JOIN
    Addresses ON FT_TBL.UserId = Addresses.UserId
ORDER BY
    Users.Recommendations
  • 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-23T22:06:00+00:00Added an answer on May 23, 2026 at 10:06 pm

    If Addresses has an ID field:

    (updated for SQL-Server)

    SELECT 
        Users.Firstname,
        Users.Surname,
        Users.UserId, 
        Users.Recommendations,
        Addresses.City,
        Addresses.Region,
        Addresses.Country
    FROM
        Users INNER JOIN
        Addresses ON Users.UserId = Addresses.UserId
    WHERE Addresses.ID = 
        ( SELECT TOP 1 A2.ID
          FROM Addresses AS A2
          WHERE Users.UserId = A2.UserId
        )
    ORDER BY
        Users.Recommendations
    

    Using SQL-Server’s window and ranking functions:

    SELECT 
        Users.Firstname,
        Users.Surname,
        Users.UserId, 
        Users.Recommendations,
        Addresses.City,
        Addresses.Region,
        Addresses.Country
    FROM
        Users INNER JOIN
         ( SELECT *
                , ROW_NUMBER() OVER (PARTITION BY UserID) AS rn
           FROM Addresses
         ) AS Addresses ON Users.UserId = Addresses.UserId
                        AND Addresses.rn = 1
    ORDER BY
        Users.Recommendations
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My database has two tables, one contains a list of users, the other a
I have a database containing two tables - one, states, contains info about each
What I have is two tables inside of a mysql database. One table contains
I have a database that has two tables, one of which contains a foreign
I have two data tables. One contains all of users identifiable informaiton (username, id,
I have two databases: one contains the users: persons id name course the other
In a MySQL database I have two tables linked in a join. One table
I have two tables in my MySQL database, one is a library of all
I have two related tables in my database: Page and Tag. One Page can
I have a database with two tables, tblPlayers and tblMatches. tblPlayers contains the following

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.