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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:56:41+00:00 2026-05-25T09:56:41+00:00

I am joining 2 tables and trying to display the results. Only problem is

  • 0

I am joining 2 tables and trying to display the results. Only problem is every result is duplicated. I have 2 tables, messages and follow. Messages are what a certain user inputs, and I want it to display only to the people that follow that certain user.

Messages | Follow
-id        -id
-message   -mem1 (logged in user)
-userid    -mem2 (followed user)
-created

$display ="";
$sql = mysql_query("
SELECT * FROM messages AS me 
JOIN follow AS fl 
ON me.userid = fl.mem2 
WHERE fl.mem1 = $id (logged in user)
ORDER BY me.created 
DESC LIMIT 10
") or die(mysql_error());
while($row=mysql_fetch_array($query)){
$msgid = $row["id"];
$message = $row["message"];
$userid = $row["userid"];
$created = $row["created"];

$display .="<?php echo $userid; ?> : <?php echo $message; ?><br />
<?php echo $created; ?>";
}

In the database there are no duplicates, just on the retrieve. Thanks for the input!

Edited: Display Code

  • 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-25T09:56:42+00:00Added an answer on May 25, 2026 at 9:56 am

    You’re getting “double” results, most likely because the query results in something different then you expect.

    If I understand your table-structure correctly; you have a one-to-many relation from messages to followers.

    In your query, however, you fetch combinations of messages and followers. Each line will consist of a unique combination of message<>follower.

    In short; when a single message has two followers, you’ll get two rows in the result with the same message; but a different follower entry.

    If you want to show each message once; and then list all followers per message you can either use group-by functions (e.g group_concat) and group-by on message entries. The other possibility is to fetch the followers in a separate query once you’ve retrieved the message row, and then print the results from that query as the followers for that message.

    If you’re simply trying to get the number of followers; you can use a group-by on the UID of your message table and add a count on the UID or user ID of the follower table. (Do not that with group-by, the select * from shouldn’t be used; but separate columns can.)

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

Sidebar

Related Questions

I am having a problem sorting results from joining tables that have to be
I have a view that is joining two tables and ordering by the first
I have a relatively simple query joining two tables. The Where criteria can be
I have 3 tables: problems, categories, and a joining table for problem_categories I am
I'm trying to get a query to compare two tables by LEFT OUTER JOINing
I'm trying to link two tables. I want a user on my site to
I need to query joining tables without using the primary key(id). class User <
I'm trying to retrieve multiple rows from joining two tables where store.itemid = item_list.id.
I have a view joining 3 tables together in a chain that i need
I have a stored Procedure that works fine joining 2 tables together. I needed

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.