Home » Programming » Databases

Using the ‘UNION’ Operator in MySQL and MariaDB

mysql union

MySQL SELECT queries are commands that pull data from your database tables according to conditions each record must meet. Complex queries will often need to combine the results from two or more SELECT queries – this is what the UNION operator does. UNION Syntax SELECT column [, column2, column3…] FROM first_table UNION SELECT column [, column2, column3…] FROM second_table; Note that: Each SELECT statement must have the same number of columns in its results Data type in each of the columns must match The columns … Read more

Home » Programming » Databases

Guide to Foreign Key Constraints in MySQL and MariaDB [With Examples]

Guide to Foreign Key Constraints in MySQL

In this guide, we cover foreign key constraints in MySQL and MariaDB, along with a number of useful examples. MySQL (and its fork MariaDB) are Relational Database Management Systems (RDBMS) – Database Systems which hold data in tables which can be related to each other. Tables in an RDBMS are organized into columns that contain data in rows (also called tuples). Each row will usually have a Primary Key – a unique value to identify the row in the table. To define relationships between two rows in two different … Read more

Home » Programming » Databases

Listing Databases and Tables in MySQL and MariaDB

mysql mariadb list databases tables

This guide explains how to list databases and tables using MySQL or MariaDB using simple commands. Managing your databases from the Linux shell is quick and efficient compared to some of the bloated database management tools available. Here’s a quick primer on seeing what databases and tables you’ve got set up on your MySQL or MariaDB server. Listing Databases Once you’ve logged in to your database, simply enter the following to list your databases: SHOW DATABASES; You’ll get a list of all of the databases … Read more

Home » Programming » Databases

Postgresql: show tables, show databases, show columns, describe table

PostgreSQL is one of the best database engines for an average web project and many who moves to psql from MySQL (for example) often ask the following questions: What is the analog of “show tables” in Postgres? How can I get the list of databases in Postgres like “show databases” in MySQL? In this quick tutorial, we’ll answer these questions, along with some other common commands which are useful. PostgreSQL doesn’t work with original MySQL commands, but it gives similar functionality with its own commands: … Read more