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

  • Home
  • SEARCH
  • 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 8488395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:31:25+00:00 2026-06-10T21:31:25+00:00

I have following table structure in Mysql DB Table: Mytable ——————————– | uid |

  • 0

I have following table structure in Mysql DB
Table: Mytable

--------------------------------
| uid | locationid | projectid |
--------------------------------
|  2  |      4     |    2     | 
|  2  |      4     |    2     | 
|  2  |      3     |    5     | 
|  2  |      3     |    5     | 
|  2  |      1     |    2     | 
|  2  |      1     |    2     | 
|  2  |      1     |    2     | 
|  2  |      1     |    1     | 
|  3  |      1     |    5     | 
|  3  |      1     |    2     | 
|  3  |      1     |    1     | 
|  3  |      1     |    1     | 
|  7  |      3     |    1     | 
|  5  |      1     |    5     | 
|  6  |      4     |    2     | 
|  5  |      1     |    5     | 
|  3  |      4     |    1     | 
|  3  |      3     |    3     | 
|  7  |      4     |    2     | 
|  7  |      4     |    3     | 

Say I passed uid=2 then for uid=2 unique combination of locationid and projectid is this

|  2  |      4     |    2     | 
|  2  |      3     |    5     | 
|  2  |      1     |    2     | 
|  2  |      1     |    1     | 

Now I want all uids with above locationid and projectid combination match. Means result should be

|  3  |      1     |    2     | 
|  3  |      1     |    1     | 
|  3  |      1     |    1     | 
|  6  |      4     |    2     | 
|  7  |      4     |    2     | 

If I pass uid=3 then result should be

|  2  |      1     |    2     | 
|  2  |      1     |    2     | 
|  2  |      1     |    2     | 
|  2  |      1     |    1     | 
|  5  |      1     |    5     | 
|  5  |      1     |    5     | 

For this I used following query but it gives wrong result as locationid and projectid combination is not match properly

 SELECT a.*
 FROM Mytable a, Mytable b 
 WHERE a.locationid = b.locationid
 AND a.projectid = b.projectid
 AND a.locationid IN (SELECT DISTINCT locationid FROM Mytable WHERE uid=$pmid)
 AND a.projectid IN(SELECT DISTINCT projectid FROM Mytable WHERE uid=$pmid)
 AND a.uid !=$pmid

Here $pmid is uid value which I passed. What is wrong with my query? Is my query is right?
Please help me.

Thanks in advance.

  • 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-10T21:31:26+00:00Added an answer on June 10, 2026 at 9:31 pm

    Try this query –

    SELECT t1.* FROM mytable t1
      JOIN (SELECT * FROM mytable WHERE uid = 2 GROUP BY locationid, projectid) t2
        ON t1.uid <> t2.uid AND
           t1.locationid = t2.locationid AND
           t1.projectid = t2.projectid;
    

    Specify your uid in WHERE clause (second line).

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

Sidebar

Related Questions

Lets say I have the following MySQL structure: CREATE TABLE `domains` ( `id` INT(10)
I have the following table structure (in MySQL): DocID, Code, IsDup, DopOf , where
I have the following MySQL table structure: num field company phone website 1 Gas
I have a MySQL table with a structure like the following: I'm looking for
I have a MySQL database with the following table structure: TransactionType : Transaction_Amount, Transaction_ID,
I have a MySQL tag-mapping table with structure from the following post - Recommended
In MySQL, is it bad to have a table structure like the following... Table
I have the following MySQL structure (minimized a lot): CREATE TABLE `site_movies` ( `id`
I have the following table structure in my db (MySQL): id group_id item_id project_id
I have the following structure with a MySQL table: +----------------+----------------+----------+ | zipcode | city

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.