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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:57:29+00:00 2026-05-16T03:57:29+00:00

I am having trouble with a mysql query. I want to get a unique

  • 0

I am having trouble with a mysql query. I want to get a unique pairing of names that share the same tenant_group_id number. All you need to know is that each tenant has a unique individual_tenant_id and up to two individual tenants share the same tenant_group_id.

   SELECT t1.first_name, t2.first_name  
     FROM individualtenant t1  
LEFT JOIN individualtenant t2 ON t1.tenant_group_id = t2.tenant_group_id
                             AND t1.individual_tenant_id != t2.individual_tenant_id

Right now this is giving me pairs but both ways, for example, it would return “John”, “Melissa” and “Melissa”, “John” but I only need a unique pairing.

EDIT: And if the individualtenant does not have a partner I need to have NULL in the second column.

  • 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-16T03:57:30+00:00Added an answer on May 16, 2026 at 3:57 am

    Doing it with a LEFT JOIN where a NULL could be either ‘no second tenant’ or ‘matched on previous ordering of tenants’ could be quite tricky, and I’m not sure how to handle those. However, if this is all the data you need, and there’s no need to fetch further data from other tables, we could cheat a little bit (which would be a separated list of N values, 1 or more):

    SELECT GROUP_CONCAT(first_name)
    FROM individualtenant
    GROUP BY tenant_group_id;
    

    Another dirty, dirty cheat would be (with only 1 or 2 tenants):

    SELECT MIN(first_name), IF(COUNt(*) > 1,MAX(first_name),NULL)
    FROM individualtenant
    GROUP BY tenant_group_id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble forming a MySQL query that performs the following action: Select all
I am having trouble with the following MYSQL query and are hoping that there
I am having trouble getting teh results i want from this mysql query. And
I am having trouble pulling a query where i want to return results that
I am having trouble getting well formatted results from my mysql query. Here is
I'm trying to query a MySQL database using an array but I'm having trouble!
Having trouble with a mysql grant statement. I want a user who has: readonly
I'm having trouble opening MySQL's slow query log with PHP. I'm writing a debugger
I'm having trouble with a stubborn MySQL query. It's a quite long and complex
I am trying to run a MySQL query but I am having trouble with

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.