SQL ET POSTGRE 5.25 : selection of requests
Now that we have built and populated our film database, we are going to learn how to query data from our tables. We open the film database in pgAdmin, right-click on it and open the Query Tool — that is where we will write our SELECT queries.
From SELECT * to chosen columns
The simplest form returns every column and every row of a table:SELECT * FROM realisateur;. Running this query gives us the full list of directors with all their attributes — id, first name, last name, date of birth and nationality. The star (*) means "give me every column".
SELECT * FROM realisateur;
SELECT prenom FROM realisateur;
SELECT prenom, nom FROM realisateur;
SELECT *— all columns of the table.SELECT <column>— only that column.- Comma-separated column list — several columns at once.
SELECT prenom FROM realisateur; returns just the first names. To pull several columns at the same time, we list them separated by commas: SELECT prenom, nom FROM realisateur; returns both first and last names for every row. You can extend the list to as many columns as you need. This is the most basic SELECT query for retrieving data; the next videos will introduce more advanced syntax such as WHERE, logical operators and more.
Summary
This lesson introduces the fundamental SELECT statement for retrieving data from PostgreSQL tables. Students learn to select all columns using SELECT *, retrieve a single column (e.g., SELECT prenom FROM réalisateur), and select multiple columns by separating them with commas. The lesson demonstrates these basic queries in PostgreSQL's query editor and establishes the foundation for more complex SELECT statements in future lessons.
Key points
- SELECT * FROM table_name retrieves all columns and all rows from a table
- SELECT specific_column FROM table_name selects data from a single column only
- Multiple columns can be selected in one query by listing column names separated by commas
- The query editor is accessed by right-clicking the database and selecting Query Tool
- Column names must be separated by commas when selecting multiple columns (e.g., SELECT prenom, nom FROM réalisateur)
- More complex SELECT queries will be covered in subsequent lessons
FAQ
How do you select all columns and data from a table in PostgreSQL?
Use the syntax SELECT * FROM table_name. The asterisk (*) represents all columns, and the query returns every row and column from the specified table.
How do you select multiple specific columns from a table?
List the column names separated by commas in your SELECT statement, such as SELECT prenom, nom FROM réalisateur to retrieve the first name and last name columns.
Where do you write and execute SELECT queries in PostgreSQL?
In the query editor, which you can access by right-clicking on your database and selecting the Query Tool option.