Categories: MySQL

MySQL ORDER BY & LIMIT

Share

To sort a table columns in ascending or descending order you use ORDER BY clause.

Using ASC and DESC you can get the result in ascending or descending order. You can also apply both order for different columns at the same time.

ORDER BY EXAMPLE:

SELECT name, address FROM users WHERE state = 'AL' ORDER BY user_id DESC, post_date ASC;

Using LIMIT clause you can get limited rows from the table. It accepts two parameters i.e. offset and count.

– offset specifies the offset of the first row to return
– count specifies the no of rows to return from the offset

SELECT name, address FROM users WHERE state = 'AL' LIMIT 0,10;

is same as

SELECT name, address FROM users WHERE state = 'AL' LIMIT 10;

Or use

SELECT name, address FROM users WHERE state = 'AL' LIMIT 5,10;

Recent Posts

What Is Commonly Misdiagnosed as Pink Eye: Understanding Eye Conditions and Their Symptoms

Introduction: Pink eye, or conjunctivitis, is a common eye condition characterized by redness and inflammation…

10 hours ago

Why Flexible Financing is the Future of Small Business

Small businesses are the backbone of the economy. Still, they often face daunting hurdles when…

17 hours ago

Warm Comfort: Choosing the Best Hot Water Bottle for Cozy Nights

Introduction: As the chill of winter settles in or a bout of cold weather strikes,…

1 day ago

One Location, Different Perspectives: The Allure of Dubai Marina Apartments

Nestled along the glittering waterfront of the City of Gold, Dubai Marina beckons to discerning…

1 day ago

How to launch a successful online dating app?

If you want to open a match-making dating app in the wide digital market and…

2 days ago

Role Of Gojek Clone In Growth Campaigns For Your Business

When was the last time you heard that a clone app like Gojek could efficiently…

2 days ago