Monday, January 9, 2012

SQL SELECT


Use CommunityAssist

Select Lastname, Firstname 
From Person;

Select * From Person

Select lastname as [Last Name], 
Firstname as [First Name]
From Person

--if there are no special characters or spaces
--you don't need brackets
Select lastname Surname, 
Firstname Name
From Person

/*this is a multi line
comment */

Select Distinct PersonKey from Donation
Order by PersonKey Desc

Select * from Donation
Order by donationAmount Desc

Select * from Donation
Order by 3 Desc

Select Top 10 DonationKey, DonationAmount
From Donation
Order by DonationAmount Desc

Select DonationKey, donationAmount
From Donation
Where DonationAmount > 1000

-- > < >= <= != <>

Select * From PersonAddress
Where City='Seattle'

Select * From PersonAddress
Where not City='Seattle'

Select * from Donation
Where DonationDate='2/2/2010'

Select * from Donation
Where DonationDate between '2/2/2010' And '2/6/2010'

Select * From PersonAddress
Where City='Kent' or City='Bellevue'

Select * From PersonContact
Where ContactInfo LIKE '306%'
-- _ for a single character ITC22_ 220 222 224 226

Select * From Donation
Where EmployeeKey in (3, 4, 5)

Select * from PersonAddress
Where Apartment is Not Null

No comments:

Post a Comment