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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:45:14+00:00 2026-05-16T05:45:14+00:00

I have a table with 3 cols, incremeting id, name, and data What i’m

  • 0

I have a table with 3 cols, incremeting id, name, and data

What i’m trying to achieve

you enter a $name… and returns $data…
then
it takes $data and finds all $names that have the same $data.

SELECT * FROM table WHERE name ='$name' data='$data' and data!='0'

does not seem to cut it..

I’m basically trying to get all rows that have the same data as the entered $name’s $data.

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-05-16T05:45:15+00:00Added an answer on May 16, 2026 at 5:45 am

    You may want to try the following:

    SELECT  t2.name
    FROM    `table` t1
    JOIN    `table` t2 ON (t2.data = t1.data)
    WHERE   t1.name = '$name' AND t1.data != '0';
    

    Test case:

    CREATE TABLE `table` (id int, name varchar(10), data varchar(10));
    
    INSERT INTO `table` VALUES (1, 'name1', 'data-a');
    INSERT INTO `table` VALUES (2, 'name2', 'data-b');
    INSERT INTO `table` VALUES (3, 'name3', 'data-a');
    INSERT INTO `table` VALUES (4, 'name4', 'data-b');
    INSERT INTO `table` VALUES (5, 'name5', 'data-a');
    

    Result:

    SELECT  t2.name
    FROM    `table` t1
    JOIN    `table` t2 ON (t2.data = t1.data)
    WHERE   t1.name = 'name2' AND t1.data != '0';
    
    +-------+
    | name  |
    +-------+
    | name2 |
    | name4 |
    +-------+
    2 rows in set (0.00 sec)
    

    The nested query solution suggested by @Borealid is another valid solution that returns the same result:

    SELECT  name 
    FROM    `table` 
    WHERE   data IN (SELECT data FROM `table` WHERE name = 'name2');
    
    +-------+
    | name  |
    +-------+
    | name2 |
    | name4 |
    +-------+
    2 rows in set (0.00 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table of data with two cols id and name. I'm trying
I have table in data base name train delay, with columns train number(int), DelayTime(int),
i work with php/Mysql i have table with two cols (date , cash) with
I have table definition like below: Place (id, name) Review (id, userid, placeid) Favorite
I have table with 50 entries (users with such details like Name Surname Location
I have table rows of data in html being filled from a CGI application.
I have events table which include so many cols besides Id PK and table
I have a security log table with 4 cols: UserID, LOGINDate, LOGINTime, ClickEvents Now
I have the following: TABLE: topics COLS: topicId, categoryId (linking to the categoryId in
I have one table which display data as from Dynamic Content, I want to

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.