Forums Get help. Give help.

Inner join vs two select statements
  • DanielMortzenDanielMortzen February 21
    Hey peeps!

    Not so much a php problem, more of a general SQL performance question.

    So i'll have two tables, one with say user information with a unique userID, and another table with all other kinds of meta-data along with which user created it (the userID again).

    Now, when i want to display the username of the person (which is in the user-table) based off the userID in the meta-data table:
    Would i be better off using an inner join statement fetching the data i need from the users table, or just do it say via a php function that returns me a username based off of a userID (essentially another db-query)?

    It's not really gonna be huge amounts of traffic, i'm just sort of wondering what the best approach would be performance-wise anyways.

    Cheers for now!
  • TT_MarkTT_Mark February 22
    Always a join for this kind of thing. The fewer SQL queries you have to perform on a page the better performance will be, within reason.
  • DanielMortzenDanielMortzen February 22
    Yeah that's kind of what i figured as well. It's just that it's kind of easy and handy programmingwise later just having a function for fetching usernames etc, but i think i'll just make a habit out of always fetching usernames etc via Inner Joins in the future on those kind of queries.

    Cheers for the reply. :)



Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

Tips

Just some helpful hints to get the most out of the forums.