SQL for Beginners

PostgreSQL Example – How to Retrieve Subset Of Columns

Retrieve Subset Of Columns Create Table – Create table called adventurers CREATE TABLE adventurers ( – string variable name varchar(255), – integer variable age int, – string variable race varchar(255), – string variable weapon varchar(255) ) Insert Rows – Insert into the table adventurers INSERT INTO adventurers (name, age, race, weapon) VALUES (‘Fjoak Doom-Wife’, 28, …

PostgreSQL Example – How to Retrieve Rows Based On Multiple Condition

Retrieve Rows Based On Multiple Condition Create Table – Create table called adventurers CREATE TABLE adventurers ( – string variable name varchar(255), – integer variable age int, – string variable race varchar(255), – string variable weapon varchar(255) Insert Rows – Insert into the table adventurers INSERT INTO adventurers (name, age, race, weapon) VALUES (‘Fjoak Doom-Wife’, …

PostgreSQL Example – How to Retrieve Rows Based On Condition

Retrieve Rows Based On Condition Create Table – Create table called adventurers CREATE TABLE adventurers ( – string variable name varchar(255), – integer variable age int, – string variable race varchar(255), – string variable weapon varchar(255) ) Insert Rows – Insert into the table adventurers INSERT INTO adventurers (name, age, race, weapon) VALUES (‘Fjoak Doom-Wife’, …

PostgreSQL Example – How to Retrieve Random Subset Of Rows

Retrieve Random Subset Of Rows Note: This code works in PostgreSQL databases, but might not work in other SQL database systems (e.g. MySQL). Create Table – Create table called adventurers CREATE TABLE adventurers ( – string variable name varchar(255), – integer variable age int, – string variable race varchar(255), – string variable weapon varchar(255) ) …

PostgreSQL Example – How to Replace Missing Values

Replace Missing Values Create Table – Create table called adventurers CREATE TABLE adventurers ( – string variable name varchar(255), – integer variable age int, – string variable race varchar(255), – string variable weapon varchar(255) ) Insert Rows With Missing Values – Insert into the table adventurers INSERT INTO adventurers (name, age, race, weapon) VALUES (‘Fjoak …

PostgreSQL Example – How to Rename Columns In Views

Rename Columns In Views Create Table – Create table called adventurers CREATE TABLE adventurers ( – string variable name varchar(255), – integer variable age int, – string variable race varchar(255), – string variable weapon varchar(255) ) Insert Rows – Insert into the table adventurers INSERT INTO adventurers (name, age, race, weapon) VALUES (‘Fjoak Doom-Wife’, 28, …

PostgreSQL Example – How to List Index Columns

List Index Columns Create Table Of Elves – Create table called elves CREATE TABLE elves ( – string variable name varchar(255), – integer variable age int, – string variable race varchar(255), – string variable alive varchar(255) ) Insert Rows Into Elf Table INSERT INTO elves (name, age, race, alive) VALUES (‘Dallar Woodfoot’, 25, ‘Elf’, ‘Yes’), …

PostgreSQL Example – How to Use If Else

If Else Create Table – Create table called adventurers CREATE TABLE adventurers ( – string variable name varchar(255), – integer variable age int, – string variable race varchar(255), – string variable weapon varchar(255) ) Insert Rows – Insert into the table adventurers INSERT INTO adventurers (name, age, race, weapon) VALUES (‘Fjoak Doom-Wife’, 28, ‘Human’, ‘Axe’), …