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

  • Home
  • SEARCH
  • 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 770329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:28:57+00:00 2026-05-14T18:28:57+00:00

Here i need help with joins. I have two tables say articles and users.

  • 0

Here i need help with joins.
I have two tables say articles and users.
while displaying articles i need to display also the user info like username, etc.
So will it be better if i just use joins to join the articles and user tables to fetch the user info while displaying articles like below.

SELECT a.*,u.username,u.id FROM articles a JOIN users u ON u.id=a.user_id

OR can this one in php.
First i get the articles with below sql

SELECT * FROM articles

Then after i get the articles array i loop though it and get the user info inside each loop like below

SELECT username, id FROM users WHERE id='".$articles->user_id."';

Which is better can i have explanation on why too.
Thank you for any reply or views

  • 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-14T18:28:58+00:00Added an answer on May 14, 2026 at 6:28 pm

    There is a third option. You could first get the articles:

     SELECT * FROM articles
    

    Then get all the relevant user names in one go:

     SELECT id, username FROM users WHERE id IN (3, 7, 19, 34, ...)
    

    This way you only have to hit the database twice instead of many times, but you don’t get duplicated data. Having said that, it seems that you don’t have that much duplicated data in your queries anyway so the first query would work fine too in this specific case.

    I’d probably choose your first option in this specific case because of its simplicity, but if you need more information for each user then go with the third option. I’d probably not choose your second option as it is neither the fastest nor the simplest.

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

Sidebar

Related Questions

I need some help formulating this query. I have two (relevant) tables, which I
I have two tables user (one) and transaction (many) and I need to get
I really need help here. I'm desperate at this point. I have NSOperation that
I need help with CMD scripts. Here is my problem: I have list of
I have two tables on different servers, and I'd like some help finding an
Please click here for sample tables and description . I have two tables ‘VEHICLE’
BeautifulSoup newbe... Need help Here is the code sample... from mechanize import Browser from
I need help with a weird runtime error. Here's the code which gives it:
need help to create regular expression matching string www.*.abc.*/somestring Here * is wild card
I need help making AOP work. What am I missing here? <?xml version=1.0 encoding=UTF-8?>

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.