Monday, April 11, 2016

Selects Part One

Use Community_Assist;

Select PersonLastName, PersonFirstName, PersonEmail
From Person

Select * From Person

Select * from Person
Order by PersonLastName 

Select * from Person
Order by PersonLastName DESC

Select * from Person
Order by PersonLastName DESC, PersonFirstName 

--column aliasing
Select PersonLastName as [Last Name],
PersonFirstName as [First Name],
PersonEmail as Email
From person

Select PersonLastName "Last Name",
PersonFirstName [First Name],
PersonEmail Email
From person

--concatenation 
Select PersonLastName + ', ' + PersonFirstName as Name, 
PersonEmail as Email
From Person

--Where clauses
Select * From PersonAddress 
Where PersonAddressCity = 'Seattle'

Select * From Donation
Where DonationDate >'8/9/2015' And DonationDate < '8/10/2015'

Select * From Donation
Where DonationDate between'8/9/2015' And '8/10/2015'

Select * from Donation
Where DonationAmount > 1000

Select * from PersonAddress 
Where Not PersonAddressCity ='Seattle'

--c language not -- not ansi standare
Select * from PersonAddress 
Where PersonAddressCity !='Seattle'

--visual basic not--not ansi standard
Select * from PersonAddress 
Where PersonAddressCity <>'Seattle'

Select * from PersonAddress
Where PersonAddressApt is null

Select * from PersonAddress
Where PersonAddressApt is not null

Select PersonLastName, PersonFirstName, PersonEmail
From Person
Where PersonLastName like 'H%'

Select PersonLastName, PersonFirstName, PersonEmail
From Person
Where PersonLastName like '%and%'
AND PersonFirstName='Martin'

Select top 10 DonationAmount, DonationDate
From Donation
Order by DonationAmount DESC

Select DonationAmount, DonationDate
From Donation
Order by DonationAmount DESC
Offset 10 rows Fetch next 10 rows only

--distinct eliminates duplicate rows
Select Distinct GrantTypeKey from GrantRequest
order by GrantTypeKey

Select Distinct EmployeeKey from DonationCheck
Order by EmployeeKey


No comments:

Post a Comment