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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:28:42+00:00 2026-06-09T06:28:42+00:00

I am trying to grasp the topic of joining tables in SQL. I know

  • 0

I am trying to grasp the topic of joining tables in SQL. I know there are multiple joins but not sure which to implement here:

Here is my SQL line in php:

$sql=mysql_query("
SELECT * FROM comments 
WHERE item_id = '{$item_id}' 
   AND review > '' 
ORDER BY good DESC, rate_id ASC");

This is what I want to join with: Another table called “users”. *”users” and “comments” both have a column called “user_id” to join.* I want to associate those two to find the full “username” in the users table.

I know SELECT is not best practice; but for the sake of this demo, can you include that here? I also know MySQL injection possibilities to watch for. **

  • 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-09T06:28:44+00:00Added an answer on June 9, 2026 at 6:28 am

    I’d recommend you to use the ANSI SQL-92 format rather than ANSI SQL-89. Try this one:

    SELECT a.* , b.*
    FROM comments a
            INNER JOIN users b
                ON a.user_id = b.user_id
    WHERE item_id = '{$item_id}'  AND 
          review > '' 
    ORDER BY good DESC, rate_id ASC
    

    Good Definition of JOINs
    Read something here: INNER JOIN (ANSI SQL-89 vs ANSI SQL-92)

    Additional Information:

    Since you are using PHP for this, I’ll also recommend to use PHP PDO Technology

    an example for that is:

    <?php
    
    
    $stmt = $dbh->prepare("SELECT a.* , b.*
        FROM comments a
                INNER JOIN users b
                    ON a.user_id = b.user_id
        WHERE item_id = ?  AND 
              review > ? 
        ORDER BY good DESC, rate_id ASC");
    
    $stmt->bindParam(1, $item_id);
    $stmt->bindParam(2, '');
    $stmt->execute();
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just trying to grasp the MVC by doing ... and still not sure got
I've been reading the javadocs trying to grasp around the swing Document API but
I'm new to the MVC pattern but have been trying to grasp it, for
I'm trying to grasp the Open/Closed principle (in my case for PHP, but that
I am trying to grasp the concept of PHP functions. I know how to
I'm a Sql Server Service Broker novice and I'm trying to grasp the best
Specifically I am trying to grasp how SQL statements differ from normal C style
I've been trying to get a grasp on writing tests, but having a lot
I am currenlty trying to grasp the concept of multiple virtual/non-virtual inheritance in c++.
I'm trying to grasp UTF-8 and charset encoding in general, but it's tricky This

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.