Miomir Dancevic Miomir Dancevic - 2 months ago 7
MySQL Question

Error in my MYSQL querrie?

Trying some querie on database, but i have a problem?
Can somebody help me with proper querie, 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