Hello friend I have a problem. My id is ’28’ and I want to show only where has this id, its has first object. How can I make this type of SQL?

WP sql:

$rows = $wpdb->get_results( 
        "SELECT hotels.id,hotels.hotel,reviews.hotel_id,reviews.id 
        FROM hotels 
        INNER JOIN reviews ON hotels.id = reviews.hotel_id" );
        var_dump($rows);

var_dump

 array (size=4)
      0 => 
        object(stdClass)[710]
          public 'id' => string '28' (length=2)
          public 'hotel' => string 'xxxxx' (length=14)
          public 'hotel_id' => string '17' (length=2)
      1 => 
        object(stdClass)[709]
          public 'id' => string '29' (length=2)
          public 'hotel' => string 'xxxxxx' (length=14)
          public 'hotel_id' => string '17' (length=2)

Read more here: Inner joins SQL in WP environment with where id =id


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: