0

There is a syntax error while using ORDER and LIMIT. I am not familiar with mysql can you point out the error.

ps = con.prepareStatement("Select product_id,image_name,images.product_name,price,"
                       + "company_name from images,products"
                       + "where images.product_name = products.product_name ORDER BY hits DESC LIMIT 5");
0

1 Answer 1

3

The problem is that you don't have a space between products and where when you concatenate the strings, so the query ends up looking like

... from images,productswhere images.product_name = ...

Add a space to one of the strings:

ps = con.prepareStatement("Select product_id,image_name,images.product_name,price,"
                       + "company_name from images,products"
                       + " where images.product_name = products.product_name ORDER BY hits DESC LIMIT 5");

You don't say what programming language you're using, but many allow strings to span lines, so you don't need the concatenation. You can then write:

ps = con.prepareStatement("Select product_id,image_name,images.product_name,price,company_name 
                        from images,products
                        where images.product_name = products.product_name
                        ORDER BY hits DESC LIMIT 5");
Sign up to request clarification or add additional context in comments.

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.