PostgreSQL Commands
Select Statement
select * from users; - Selects all column
select username from users; - Selects only username column
select * from users limit 10; - Selects only first 10 records
Here column name is case insensitive
e.g username = USERNAME
Columns name with space in between must be same as what is stored in database
e.g. “User Name” is not equal to “user name”. You should enter “User Name” in query
Where Filter
select * from users where country=’europe’; - Selects all column from users table whose country column values is europe
select * from users where country=’europe’ limit 10; - Selects first 10 records from users table whose country column values is europe
select * from users where “Annual Salary” > 10000;
Use logical operator on number columns to perform numeric operations
Selects first 10 users whose birth year is 2015
Dynamic And/Or Filters
Check max value of column dynamically
Here is check maximum year of birthdate from users table
Then returns first 10 records whose birth year = calculated max year
Check max value of column dynamically along with logical operator
Here is check maximum year of birthdate from users table
Then returns first 10 records whose birth year = calculated max year
Logical and + or operator
Where - with %string%
To select records with country name having space in between e.g Sri Lanka
To select records with country name having space at end
e.g ‘India ‘(space at the end added)
Order by
Order by on string column
Order by descending on number column
Sum
Distinct
To get non repeating values of selected table , we use distinct. Below query gives u all column country from al records
To check non repeating/ unique values
Comments
Post a Comment