Dino Geek, try to help you

How to use unions in MariaDB?


Unions in MariaDB are used to combine the result of two or more SELECT statements. However, there are rules that need to be followed when using unions:

1. Each SELECT statement within the UNION must have the same number of columns.
2. The columns must also have similar data types.
3. The columns in each SELECT statement must also be in the same order.

Here is a basic example of how to use unions in MariaDB:

```
SELECT column_name FROM table1
UNION
SELECT column_name FROM table2;
```

This will return a list of the distinct values of `column_name` from both `table1` and `table2`.

If you want to select all values from both tables, including duplicates, you can use `UNION ALL`, like this:

```
SELECT column_name FROM table1
UNION ALL
SELECT column_name FROM table2;
```

This will return all values of `column_name` from both `table1` and `table2`, including duplicates.

It’s important to note that the UNION operator only returns distinct values. UNION ALL returns all values.

Also, the result-set of a UNION is sorted ascending by default. If you want to change the order you can add an ORDER BY statement as follows:

```
SELECT column_name FROM table1
UNION
SELECT column_name FROM table2
ORDER BY column_name DESC;
```

This will return a list of the distinct values of `column_name` from both `table1` and `table2`, sorted in descending order.


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