| ==== |
| ---- QUERY |
| select * from country_postgres; |
| ---- RESULTS |
| 1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00 |
| 2,'Russia',false,20,200,2000,20000,2.200000047683716,2.22,2024-02-01,'RU',2024-02-01 11:00:00 |
| 3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00 |
| ---- TYPES |
| INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP |
| ==== |
| ---- QUERY |
| select * from country_keystore_postgres; |
| ---- RESULTS |
| 1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00 |
| 2,'Russia',false,20,200,2000,20000,2.200000047683716,2.22,2024-02-01,'RU',2024-02-01 11:00:00 |
| 3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00 |
| ---- TYPES |
| INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP |
| ==== |
| ---- QUERY |
| select id, name, date_col from country_postgres; |
| ---- RESULTS |
| 1,'India',2024-01-01 |
| 2,'Russia',2024-02-01 |
| 3,'USA',2024-03-01 |
| ---- TYPES |
| INT, STRING, DATE |
| ==== |
| ---- QUERY |
| select id, name, date_col from country_keystore_postgres; |
| ---- RESULTS |
| 1,'India',2024-01-01 |
| 2,'Russia',2024-02-01 |
| 3,'USA',2024-03-01 |
| ---- TYPES |
| INT, STRING, DATE |
| ==== |
| ---- QUERY |
| select count(*) from country_postgres; |
| ---- RESULTS |
| 3 |
| ---- TYPES |
| BIGINT |
| ==== |
| ---- QUERY |
| select count(*) from country_keystore_postgres; |
| ---- RESULTS |
| 3 |
| ---- TYPES |
| BIGINT |
| ==== |
| ---- QUERY |
| select distinct name from country_postgres; |
| ---- RESULTS |
| 'India' |
| 'Russia' |
| 'USA' |
| ---- TYPES |
| STRING |
| ==== |
| ---- QUERY |
| select distinct name from country_keystore_postgres; |
| ---- RESULTS |
| 'India' |
| 'Russia' |
| 'USA' |
| ---- TYPES |
| STRING |
| ==== |
| ---- QUERY |
| # Check for null values |
| select * from country_postgres where string_col IS NULL; |
| ---- RESULTS |
| ---- TYPES |
| INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP |
| ==== |
| ---- QUERY |
| select * from country_keystore_postgres where string_col IS NULL; |
| ---- RESULTS |
| ---- TYPES |
| INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP |
| ==== |
| ---- QUERY |
| # Order by integer column |
| select id, name, int_col from country_postgres order by int_col DESC; |
| ---- RESULTS |
| 3,'USA',3000 |
| 2,'Russia',2000 |
| 1,'India',1000 |
| ---- TYPES |
| INT, STRING, INT |
| ==== |
| ---- QUERY |
| select id, name, int_col from country_keystore_postgres order by int_col DESC; |
| ---- RESULTS |
| 3,'USA',3000 |
| 2,'Russia',2000 |
| 1,'India',1000 |
| ---- TYPES |
| INT, STRING, INT |
| ==== |
| ---- QUERY |
| # Select using case statement |
| select id, name, case when bool_col then 'Active' else 'Inactive' end as status from country_postgres; |
| ---- RESULTS |
| 1,'India','Active' |
| 2,'Russia','Inactive' |
| 3,'USA','Active' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select id, name, case when bool_col then 'Active' else 'Inactive' end as status from country_keystore_postgres; |
| ---- RESULTS |
| 1,'India','Active' |
| 2,'Russia','Inactive' |
| 3,'USA','Active' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| # Check for minimum date |
| select min(date_col) from country_postgres; |
| ---- RESULTS |
| 2024-01-01 |
| ---- TYPES |
| DATE |
| ==== |
| ---- QUERY |
| select min(date_col) from country_keystore_postgres; |
| ---- RESULTS |
| 2024-01-01 |
| ---- TYPES |
| DATE |
| ==== |
| ---- QUERY |
| # Join with a self table alias |
| select a.id, a.name, b.name from country_postgres a join country_postgres b on a.id <> b.id; |
| ---- RESULTS |
| 1,'India','Russia' |
| 1,'India','USA' |
| 2,'Russia','India' |
| 2,'Russia','USA' |
| 3,'USA','India' |
| 3,'USA','Russia' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.name from country_keystore_postgres a join country_keystore_postgres b on a.id <> b.id; |
| ---- RESULTS |
| 1,'India','Russia' |
| 1,'India','USA' |
| 2,'Russia','India' |
| 2,'Russia','USA' |
| 3,'USA','India' |
| 3,'USA','Russia' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| # Left join with another table |
| select a.id, a.name, b.string_col from country_postgres a left join country_keystore_postgres b on a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.string_col from country_keystore_postgres a left join country_postgres b on a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| # Right join with another table |
| select a.id, a.name, b.string_col from country_postgres a right join country_keystore_postgres b on a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.string_col from country_keystore_postgres a right join country_postgres b on a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| # Full outer join |
| select a.id, a.name, b.string_col from country_postgres a full outer join country_keystore_postgres b on a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.string_col from country_keystore_postgres a full outer join country_postgres b on a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| # Using IN clause |
| select * from country_postgres where name IN ('India', 'USA'); |
| ---- RESULTS |
| 1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00 |
| 3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00 |
| ---- TYPES |
| INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP |
| ==== |
| ---- QUERY |
| select * from country_keystore_postgres where name IN ('India', 'USA'); |
| ---- RESULTS |
| 1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00 |
| 3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00 |
| ---- TYPES |
| INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP |
| ==== |
| ---- QUERY |
| select * from country_postgres_query; |
| ---- RESULTS |
| 1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00 |
| 2,'Russia',false,20,200,2000,20000,2.200000047683716,2.22,2024-02-01,'RU',2024-02-01 11:00:00 |
| 3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00 |
| ---- TYPES |
| INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP |
| ==== |
| ---- QUERY |
| select * from country_keystore_postgres_query; |
| ---- RESULTS |
| 1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00 |
| 2,'Russia',false,20,200,2000,20000,2.200000047683716,2.22,2024-02-01,'RU',2024-02-01 11:00:00 |
| 3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00 |
| ---- TYPES |
| INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP |
| ==== |
| ---- QUERY |
| select id, name, date_col from country_postgres_query; |
| ---- RESULTS |
| 1,'India',2024-01-01 |
| 2,'Russia',2024-02-01 |
| 3,'USA',2024-03-01 |
| ---- TYPES |
| INT, STRING, DATE |
| ==== |
| ---- QUERY |
| select id, name, date_col from country_keystore_postgres_query; |
| ---- RESULTS |
| 1,'India',2024-01-01 |
| 2,'Russia',2024-02-01 |
| 3,'USA',2024-03-01 |
| ---- TYPES |
| INT, STRING, DATE |
| ==== |
| ---- QUERY |
| select count(*) from country_postgres_query; |
| ---- RESULTS |
| 3 |
| ---- TYPES |
| BIGINT |
| ==== |
| ---- QUERY |
| select count(*) from country_keystore_postgres_query; |
| ---- RESULTS |
| 3 |
| ---- TYPES |
| BIGINT |
| ==== |
| ---- QUERY |
| select distinct name from country_postgres_query; |
| ---- RESULTS |
| 'India' |
| 'Russia' |
| 'USA' |
| ---- TYPES |
| STRING |
| ==== |
| ---- QUERY |
| select distinct name from country_keystore_postgres_query; |
| ---- RESULTS |
| 'India' |
| 'Russia' |
| 'USA' |
| ---- TYPES |
| STRING |
| ==== |
| ---- QUERY |
| # Check for null values |
| select * from country_postgres_query where string_col IS NULL; |
| ---- RESULTS |
| ---- TYPES |
| INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP |
| ==== |
| ---- QUERY |
| select * from country_keystore_postgres_query where string_col IS NULL; |
| ---- RESULTS |
| ---- TYPES |
| INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP |
| ==== |
| ---- QUERY |
| # Order by integer column |
| select id, name, int_col from country_postgres_query order by int_col DESC; |
| ---- RESULTS |
| 3,'USA',3000 |
| 2,'Russia',2000 |
| 1,'India',1000 |
| ---- TYPES |
| INT, STRING, INT |
| ==== |
| ---- QUERY |
| select id, name, int_col from country_keystore_postgres_query order by int_col DESC; |
| ---- RESULTS |
| 3,'USA',3000 |
| 2,'Russia',2000 |
| 1,'India',1000 |
| ---- TYPES |
| INT, STRING, INT |
| ==== |
| ---- QUERY |
| # Select using case statement |
| select id, name, case when bool_col then 'Active' else 'Inactive' end as status from country_postgres_query; |
| ---- RESULTS |
| 1,'India','Active' |
| 2,'Russia','Inactive' |
| 3,'USA','Active' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select id, name, case when bool_col then 'Active' else 'Inactive' end as status from country_keystore_postgres_query; |
| ---- RESULTS |
| 1,'India','Active' |
| 2,'Russia','Inactive' |
| 3,'USA','Active' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| # Check for minimum date |
| select min(date_col) from country_postgres_query; |
| ---- RESULTS |
| 2024-01-01 |
| ---- TYPES |
| DATE |
| ==== |
| ---- QUERY |
| select min(date_col) from country_keystore_postgres_query; |
| ---- RESULTS |
| 2024-01-01 |
| ---- TYPES |
| DATE |
| ==== |
| ---- QUERY |
| # Join with a self table alias |
| select a.id, a.name, b.name from country_postgres_query a join country_postgres_query b on a.id <> b.id; |
| ---- RESULTS |
| 1,'India','Russia' |
| 1,'India','USA' |
| 2,'Russia','India' |
| 2,'Russia','USA' |
| 3,'USA','India' |
| 3,'USA','Russia' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.name from country_keystore_postgres_query a join country_keystore_postgres_query b on |
| a.id <> b.id; |
| ---- RESULTS |
| 1,'India','Russia' |
| 1,'India','USA' |
| 2,'Russia','India' |
| 2,'Russia','USA' |
| 3,'USA','India' |
| 3,'USA','Russia' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| # Left join with another table |
| select a.id, a.name, b.string_col from country_postgres_query a left join country_keystore_postgres_query b on |
| a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.string_col from country_postgres a left join country_postgres_query b on |
| a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.string_col from country_keystore_postgres a left join country_postgres_query b on |
| a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.string_col from country_keystore_postgres_query a left join country_postgres b on |
| a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.string_col from country_keystore_postgres_query a left join country_postgres_query b on |
| a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.string_col from country_postgres_query a left join country_postgres b on |
| a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.string_col from country_postgres_query a left join country_postgres_query b on |
| a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| # Right join with another table |
| select a.id, a.name, b.string_col from country_postgres_query a right join country_keystore_postgres_query b on |
| a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.string_col from country_keystore_postgres_query a right join country_postgres_query b on |
| a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.string_col from country_postgres a right join country_keystore_postgres_query b on |
| a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.string_col from country_postgres a right join country_postgres_query b on |
| a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.string_col from country_keystore_postgres a right join country_postgres_query b on |
| a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.string_col from country_keystore_postgres a right join country_keystore_postgres_query b on |
| a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| # Full outer join |
| select a.id, a.name, b.string_col from country_postgres_query a full outer join country_keystore_postgres_query b on |
| a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.string_col from country_keystore_postgres_query a full outer join country_postgres_query b on |
| a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.string_col from country_postgres a full outer join country_keystore_postgres_query b on |
| a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.string_col from country_postgres a full outer join country_postgres_query b on |
| a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.string_col from country_keystore_postgres a full outer join country_postgres_query b on |
| a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.string_col from country_keystore_postgres a full outer join country_keystore_postgres_query b on |
| a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| # Using IN clause |
| select * from country_postgres_query where name IN ('India', 'USA'); |
| ---- RESULTS |
| 1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00 |
| 3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00 |
| ---- TYPES |
| INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP |
| ==== |
| ---- QUERY |
| select * from country_keystore_postgres_query where name IN ('India', 'USA'); |
| ---- RESULTS |
| 1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00 |
| 3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00 |
| ---- TYPES |
| INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP |
| ==== |
| ---- QUERY |
| select * from quoted_col; |
| ---- RESULTS |
| 1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00 |
| 2,'Russia',false,20,200,2000,20000,2.200000047683716,2.22,2024-02-01,'RU',2024-02-01 11:00:00 |
| 3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00 |
| ---- TYPES |
| INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP |
| ==== |
| ---- QUERY |
| select id, name, date_col from quoted_col; |
| ---- RESULTS |
| 1,'India',2024-01-01 |
| 2,'Russia',2024-02-01 |
| 3,'USA',2024-03-01 |
| ---- TYPES |
| INT, STRING, DATE |
| ==== |
| ---- QUERY |
| select count(*) from quoted_col; |
| ---- RESULTS |
| 3 |
| ---- TYPES |
| BIGINT |
| ==== |
| ---- QUERY |
| select distinct name from quoted_col; |
| ---- RESULTS |
| 'India' |
| 'Russia' |
| 'USA' |
| ---- TYPES |
| STRING |
| ==== |
| ---- QUERY |
| # Check for null values |
| select * from quoted_col where `freeze` IS NULL; |
| ---- RESULTS |
| ---- TYPES |
| INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP |
| ==== |
| ---- QUERY |
| # Order by integer column |
| select id, name, int_col from quoted_col order by int_col DESC; |
| ---- RESULTS |
| 3,'USA',3000 |
| 2,'Russia',2000 |
| 1,'India',1000 |
| ---- TYPES |
| INT, STRING, INT |
| ==== |
| ---- QUERY |
| # Select using case statement |
| select id, name, case when bool_col then 'Active' else 'Inactive' end as status from quoted_col; |
| ---- RESULTS |
| 1,'India','Active' |
| 2,'Russia','Inactive' |
| 3,'USA','Active' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| # Check for minimum date |
| select min(date_col) from quoted_col; |
| ---- RESULTS |
| 2024-01-01 |
| ---- TYPES |
| DATE |
| ==== |
| ---- QUERY |
| # Join with a self table alias |
| select a.id, a.name, b.name from quoted_col a join quoted_col b on a.id <> b.id; |
| ---- RESULTS |
| 1,'India','Russia' |
| 1,'India','USA' |
| 2,'Russia','India' |
| 2,'Russia','USA' |
| 3,'USA','India' |
| 3,'USA','Russia' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| # Left join with another table |
| select a.id, a.name, b.`freeze` from quoted_col a left join quoted_col b on a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.`freeze` from quoted_col a left join quoted_col b on a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| # Right join with another table |
| select a.id, a.name, b.`freeze` from quoted_col a right join quoted_col b on a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.`freeze` from quoted_col a right join quoted_col b on a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| # Full outer join |
| select a.id, a.name, b.`freeze` from quoted_col a full outer join quoted_col b on a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| select a.id, a.name, b.`freeze` from quoted_col a full outer join quoted_col b on a.id = b.id; |
| ---- RESULTS |
| 1,'India','IN' |
| 2,'Russia','RU' |
| 3,'USA','US' |
| ---- TYPES |
| INT, STRING, STRING |
| ==== |
| ---- QUERY |
| # Using IN clause |
| select * from quoted_col where name IN ('India', 'USA'); |
| ---- RESULTS |
| 1,'India',true,10,100,1000,10000,1.100000023841858,1.11,2024-01-01,'IN',2024-01-01 10:00:00 |
| 3,'USA',true,30,300,3000,30000,3.299999952316284,3.33,2024-03-01,'US',2024-03-01 12:00:00 |
| ---- TYPES |
| INT, STRING, BOOLEAN, SMALLINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, DATE, STRING, TIMESTAMP |
| ==== |