Hi i'm trying to write a simple SQL command to use within PHP.

I want to select the whole table, sort by one of the columns, then only display the top 100 rows.

Without the WHERE rownum <=10 it works fine. But it displays the whole contents of the table rather than the top 10 from the quantity column.

Thanks

Recommended Answers

All 2 Replies

You need to use LIMIT

$sql = 'SELECT * FROM Possesions ORDER BY quantity DESC LIMIT 0,10';

I think this is helpful for you

select * from employee order by book_id  limit 7;

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.