0

I have a complex query and it was working fine before adding one more line: the working query:

         $query = "SELECT SQL_CALC_FOUND_ROWS *
                    FROM realestate
                    INNER JOIN users ON id_user = users.id
                    LEFT JOIN pic ON id_realestate = realestate.id
                    group by realestate.id
                    ORDER BY {$order}
                    LIMIT 0 , 10";

the value of $order is date DESC

after adding one more line, here is the query:

         $query = "SELECT SQL_CALC_FOUND_ROWS *
                    FROM realestate
                    {$place} 
                    INNER JOIN users ON id_user = users.id
                    LEFT JOIN pic ON id_realestate = realestate.id
                    group by realestate.id
                    ORDER BY {$order}
                    LIMIT 0 , 10";

$place has this value WHERE address =1 the field name address doesn't duplicate in other tables.
I get this mysql error :

  Database query failed: You have an error in your SQL syntax;
  check the manual that corresponds to your MySQL server version
 for the right syntax to use near
 'INNER JOIN users ON id_user = users.id LEFT JOIN pic ON id_realestate = real' 
  at line 4
0

2 Answers 2

2

JOIN clauses must come before WHERE clauses. You have your clauses in the wrong order.

Sign up to request clarification or add additional context in comments.

Comments

1

According to http://dev.mysql.com/doc/refman/5.0/en/select.html

Table References comes before the WHERE portion. The following should be the correct order:

     $query = "SELECT SQL_CALC_FOUND_ROWS *
                FROM realestate
                INNER JOIN users ON id_user = users.id
                LEFT JOIN pic ON id_realestate = realestate.id
                {$place} 
                group by realestate.id
                ORDER BY {$order}
                LIMIT 0 , 10";

JOIN statements are part of the FROM table references.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.