php - mysql inner join 3 tables

270

I am getting error. I wonder where did I go wrong? Please could you help?

$tours = mysql_query("SELECT * FROM
    tours t
    INNER JOIN tour_property_array  p
    ON
    t.tour_id = p.tour_id
    INNER JOIN tour_prices tp
    ON
    p.tour_id = tp.tour_id
    AND t.tour_status='Aktif'
    WHERE t.tour_category_id=".$category_id."
    AND t.date_month ='".$date."'
    AND p.tour_propert_id=".$propert_id." "
);
456

Answer

Solution:

  $tours = mysql_query("SELECT * FROM 
  tours t INNER JOIN tour_property_array  p ON  
  t.tour_id = p.tour_id INNER JOIN tour_prices tp  ON  
  p.tour_id = tp.tour_id  AND t.tour_status='Aktif' 
  WHERE t.tour_category_id=".$category_id." AND t.date_month ='".$date."' AND  p.tour_propert_id=".$propert_id." ");

replace it with

$tours = mysql_query("SELECT * FROM tours t INNER JOIN tour_property_array p ON
        t.tour_id = p.tour_id INNER JOIN tour_prices tp ON p.tour_id = tp.tour_id
        AND t.tour_status='Aktif' WHERE t.tour_category_id='$category_id' AND
         t.date_month ='$date' AND p.tour_propert_id='$propert_id' ");
884

Answer

Solution:

Try this one

SELECT 
    *
FROM
    tours t
        INNER JOIN
    tour_property_array p ON t.tour_id = p.tour_id
        INNER JOIN
    tour_prices tp ON p.tour_id = tp.tour_id
        AND t.tour_status = 'Aktif'
WHERE
    t.tour_category_id = '.$category_id.'
        AND t.date_month = '".$date."'
        AND p.tour_propert_id = '".$propert_id."';
982

Answer

Solution:

use this query ..
select *
from
    tableA a
        inner join
    tableB b
        on a.common = b.common
        inner join 
    TableC c
        on b.common = c.common
623

Answer

Solution:

You are Giving a condition in Join Move it to Where Clause.

SELECT 
     *
      FROM
           tours t
                INNER JOIN
                        tour_property_array p ON t.tour_id = p.tour_id
                INNER JOIN
                        tour_prices tp ON p.tour_id = tp.tour_id

      WHERE
             t.tour_category_id = '.$category_id.'
             AND t.tour_status = 'Aktif'
             AND t.date_month = '".$date."'
             AND p.tour_propert_id = '".$propert_id."';

People are also looking for solutions to the problem: php - How to fetch tasks Through Asana API

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.