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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:35:40+00:00 2026-06-12T05:35:40+00:00

I have 3 columns questionid , replyid and userid . I want to select

  • 0

I have 3 columns questionid, replyid and userid.

I want to select all questionid's from userid where userid is session[userid],
And then select distinct questionid from it.

Right now I take all those questionid belonging to $_SESSION['user_id'] in an array( and remove duplicates from it) and then
I again pass another query

foreach($array as $x)
{
$query="select questionid,replyid,userid from table where questionid=$x"
}

But I think that the above steps can be done in query itself(and the above step is not working also). I tried below but its not working.
If I try to pass this query then duplicate value still comes:

SELECT distinct(questionid),replyid,userid 
from table 
where userid=$_SESSION['user_id']

So what should be the query?

questionid,replyid,userid

8          ,2     ,45

8          ,3      ,45

9           ,8      ,41

But as 8,2 and 8,3 are in same webpage(one question and two answers), I want to avoid showing duplicate question…

So I was trying the wrong way as I was taking distinct questionid and then again selecting * from table where questionid was previous one.

But then as @ Mahmoud Gamal suggested I did

 SELECT distinct questionid, `answerid`, `userid`
 FROM `table` 
 WHERE  userid='$user' 

But again I had done the same duplicate thing. So I added limit 0,1

 SELECT distinct questionid, `answerid`, `userid`
 FROM `table`
 WHERE  userid='$user' 
 LIMIT 0,1
  • 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-12T05:35:41+00:00Added an answer on June 12, 2026 at 5:35 am

    This is the equivalent of the two queries you described in your post:

    SELECT DISTINCT questionid, replyid, userid 
    FROM table 
    WHERE questionid IN
    (
        SELECT DISTINCT questionid
        FROM table 
        WHERE userid = @user_id
    )
    

    This will give you DISTINCT questionid, replyid, userid. But this isn’t by necessary, contains DISTINCT(questionid).

    If you are looking for distinct questionid, you will end up with a GROUP BY questionid with aggregate functions for other two fields replyid, userid, like SUM, MAX or MIN.

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

Sidebar

Related Questions

i have four tables user-question contains two columns: questionID, userID, the questions that the
I have a table and want to transpose its rows to columns, similar to
I have a question about matching columns and replace this with a 1 if
I have 2 mysql tables : Question with the following columns : id, question,
I have 2 mysql tables 1. questions: with the following columns: id, title, answer1,
my question is: assuming we have a calendar_table with UNIX datestamp date_column, i want
I have columns Mon, Tue, wed, thu, fri, sat, sun with timestamps for every
I have a table products , and I have columns like product_name , product_id
I have an Answer database table below: Answer Table AnswerId SessionId QuestionId Answer 13
Ok, so say I have two tables. Question questionID QuestionDescription Answer AnswerID QuestionID AnswerDescription

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.