Dino Geek, try to help you

How to use ORDER BY and GROUP BY in MariaDB?


In MariaDB, both the ORDER BY and GROUP BY clauses are used to sort and group data returned by your SELECT statements. Here’s how you can use them:

ORDER BY:

The `ORDER BY` clause is used in a SELECT statement to sort the results either in ascending or descending order.

Syntax:

```
SELECT column(s)
FROM table
ORDER BY column(s) [ASC|DESC];
```

- ASC is used for ascending order and DESC for descending order. If you do not specify anything, ASC is assumed.

Example:

```
SELECT EmployeeName, Salary
FROM Employees
ORDER BY Salary DESC;
```
In this example, the statement will select the EmployeeName and Salary from the Employees table, and sort the result in descending order by Salary.

GROUP BY:

The `GROUP BY` statement is used with the aggregate functions (COUNT, MAX, MIN, SUM, AVG) to group the result-set by one or more columns.

Syntax:

```
SELECT column(s), aggregate_function(column)
FROM table
WHERE condition
GROUP BY column(s);
```
Example:

```
SELECT Department, COUNT
FROM Employees
GROUP BY Department;
```
In this example, it will count EmployeeID in each Department grouping.

You can also use both clauses together in a SELECT statement:

```
SELECT Department, COUNT
FROM Employees
GROUP BY Department
ORDER BY COUNT DESC;
```


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use