Fetching albums from the database
In Chapter 7, Getting Started with the Database, we were introduced to YeSQL for interacting with our database. We used YeSQL to create an INSERT
statement which added our new users to the database. Similarly, we can use YeSQL to SELECT
records from the database. If you can do it in SQL, you can do it with YeSQL. And that's the beauty of YeSQL: it's just SQL. This allows us to open an SQL tool of our choice and experiment with our query until we get it right.
Writing the SQL query
For this next bit, we'll use the psql
tool to verify our SQL. But you're free to use whatever SQL editor you have at your disposal. Take the following steps:
Launch
psql
and connect to our database:# psql -U hipstr -d postgres -h localhost
We can write our query at the PostgreSQL prompt. Any valid SQL is accepted at the prompt; we just need to terminate it with a semi-colon (;). Our feature wants to show a list of albums, the artist/s, and the release dates of those albums, all ordered...