AboSami
AboSami

Reputation: 259

How can order the result , MYSQL

I have a database with a table 'Posts Table'.

In this table there are posts id, count user comment and count visitors comment.

I want to extra the top posts which have most comments

But the problem is there is two columns for comment (users comment, visitors comment).

I want the result like this , (usercomment + visitors comment) ,

How can I use SQL to do this?

enter image description here

Upvotes: 0

Views: 62

Answers (2)

iamkrillin
iamkrillin

Reputation: 6876

SELECT * 
FROM Posts
ORDER BY UserComments + VisitorComments DESC

That ought to do the trick

Upvotes: 3

Jake Dempsey
Jake Dempsey

Reputation: 6322

select * from Posts order by UserComments + VisitorComments desc

You need the DESC otherwise I believe it defaults to ASC

Upvotes: 0

Related Questions