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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:48:24+00:00 2026-06-01T09:48:24+00:00

$sql = select body, stamp from posts where user_id = ‘$userid’ order by stamp

  • 0
$sql = "select body, stamp from posts where user_id = '$userid' order by stamp desc";

NOTE: the above query works fine. What I want to do is also select username from my users table, and display the username that matches the user_id.

I have edited the above statement like so, and it doesnt work. Can someone suggest the correct query? My goal is to also be able to display usernames. in addition to simply displaying user_id.

$sql = "select body, stamp from posts AND username from users where user_id = '$userid' order by stamp desc";

My goal is to also be able to display usernames. instead of simply user_id.

  • 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-01T09:48:25+00:00Added an answer on June 1, 2026 at 9:48 am

    You’ll need to use a JOIN to bring the two tables together on the matching field, so something like:

    $sql = "SELECT p.body, p.stamp, u.username FROM posts p INNER JOIN users u ON p.user_id=u.user_id WHERE p.user_id='$userid' ORDER BY p.stamp DESC";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this SQL: SELECT * FROM mytable ORDER BY mycolumn, RAND() Assuming that mycolumn
Is this query hackable using sql injection ? SELECT count(*) FROM mytable_fts where mytable_fts
When we fire a SQL query like SELECT * FROM SOME_TABLE_NAME under ORACLE What
My SQL query looks like this... sekect * FROM mail_headers a LEFT JOIN mail_headers_body
SQL : SELECT COUNT(usr.id) as `total_results` FROM users as usr LEFT JOIN profile as
SQL: select * from user where room_id not in (select id from rooms); what
I have the following SQL: SELECT * FROM [Database].dbo.[TagsPerItem] INNER JOIN [Database].dbo.[Tag] ON [Tag].Id
need help/guide for sql select query, I have 2 table stock and stock_history, in
How to select all columns from tables in join using linq Sql: select CTRL_RUN_JOB.*,
I have this SQL query about getting the 5 events today: SELECT n.nid, n.type,

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.