Miomir Dancevic Miomir Dancevic - 2 months ago 9
MySQL Question

Error in my MYSQL query?

Trying some queries on the database, but I have a problem. Can somebody help me with proper query?

This is what I need

SELECT
IdNews, Caption, NewsText, NumberOfViews, NumberOfComments,
PublishDate, CoinValue, category.IdNewsCategory,
NewsCategory, country.IdCountry, CountryName, news.IdUser,
FirstName, LastName, Picture, DateTimeUpCoin
FROM
news
INNER JOIN
category ON category.IdNewsCategory = news.IdNewsCategory
INNER JOIN
country ON news.IdCountry = country.IdCountry
INNER JOIN
user ON user.IdUser = news.IdUser
WHERE
news.IdCountry = 1
LIMIT 0, 10
ORDER BY
NumberOfViews DESC

Answer

You have written wrong query for Order by.

In query, LIMIT comes always last.

You need to write corrected query as per below :

SELECT
    IdNews,Caption,NewsText,NumberOfViews,NumberOfComments,
    PublishDate,CoinValue,category.IdNewsCategory,
    NewsCategory,country.IdCountry,CountryName,news.IdUser,
    FirstName, LastName,Picture, DateTimeUpCoin 
FROM news 
INNER JOIN category ON category.IdNewsCategory = news.IdNewsCategory 
INNER JOIN country ON news.IdCountry = country.IdCountry
INNER JOIN user ON user.IdUser = news.IdUser
WHERE news.IdCountry = 1
ORDER BY NumberOfViews DESC
LIMIT 0, 10
Comments