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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:46:28+00:00 2026-06-07T04:46:28+00:00

Question: Can someone help me fix the following piece of code to meet the

  • 0

Question: Can someone help me fix the following piece of code to meet the following info:

When using this query, it sees that my username is in the database multiple times on diff columns, and so it is duplicating my posts when finding them in the query. I WANT it to show posts at diff timestamps by the same person, but not display from the same person if timestamp is the same.

Might be a better way to code the query, if so, I wouldn’t mind seeing those options. Would doing a UNION query be the best way to do this?

$query = "SELECT p.* ".
"FROM posts p ".
"INNER JOIN friendships f ON p.username = f.user2 OR p.username = f.user1 ".
"WHERE f.user1 = '$sessionusername' OR f.user2 = '$sessionusername' ORDER BY id DESC"; 

SOLUTION:

I am answering my own question here, just to give someone a workable solution from what I did to fix the issue. I tried grouping by ID and then turning around and ordering by ID; however, it threw an error — so instead I am ordering by timestamp, and grouping by ID. Below is my code. Worked for me — and hopefully this ends up helping someone else!

$query = "SELECT p.*, MAX(timestamp) AS latest ".
"FROM posts p ".
"INNER JOIN friendships f ON p.username = f.user2 OR p.username = f.user1 ".
"WHERE f.user1 = '$sessionusername' OR f.user2 = '$sessionusername' GROUP BY id ORDER BY  latest DESC";   
  • 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-07T04:46:30+00:00Added an answer on June 7, 2026 at 4:46 am

    Use GROUP BY to tell mysql what entity/fields you want to be unique:

    SELECT p.*
    FROM posts p
    INNER JOIN friendships f ON (p.username = f.user2 OR p.username = f.user1)
    WHERE f.user1 = '$sessionusername' OR f.user2 = '$sessionusername' 
    GROUP BY posts.id
    ORDER BY id DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone help me with the following question: How can I find files that
QUESTION Can someone help walk me through the general approach to solving this problem?
Can someone help me out with this question: How can I use an link
Can someone help me with this very simple question. I'm very+++ beginner. This is
Can someone help me with a regular expression that would help me do this.
Quick question hopefully someone can help out here. I'm trying to copy and paste
im hoping someone can help me quickly with a question i have. As site
I am hoping someone can help me with a question i have relating to
I am hoping someone can help me out with a quick question I have
I'm hoping someone can help me with a backbone.js question. I've got most of

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.