0

could you check and tell me where i have made a mistake? Here is the code:

$sql = "SELECT prekės.* , CONCAT(vartotojai.name) as v_name
        FROM prekės 
            LEFT JOIN vartotojai
            ON vartotojai.V_ID=prekės.V_ID
        ORDER BY prekės.date
        LIMIT $offset, $rec_limit
        WHERE prekės.category='Telefonai'";

The error comes from the last line with WHERE clause.

1
  • 1
    select from join where order limit Commented May 20, 2014 at 0:18

2 Answers 2

3

Clause order is incorrect : WHERE -> ORDER -> LIMIT :

$sql = "SELECT prekės.*
             , CONCAT(vartotojai.name) as v_name
        FROM prekės LEFT JOIN vartotojai ON vartotojai.V_ID=prekės.V_ID
        WHERE prekės.category='Telefonai'
        ORDER BY prekės.date
        LIMIT $offset, $rec_limit
       ";
Sign up to request clarification or add additional context in comments.

Comments

1

Check the order. ORDER and LIMIT should go after WHERE.

In order to ensure you are crafting well designed SQL, it is a good idea to check the link I provided. Once you get it, it's actually quite easy to understand the why of it.

1 Comment

Also ORDER BY has to be after `WHERE.

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.