Looking for examples

  • Good evening I have the following code I need to execute and I can't for the life of me find any good examples for the where clause. I'm new to SQL and I would be grateful if someone could point me in the right direction the following is what I have;
    SELECT [ZipCode]
    FROM [Address]
    WHERE []
    ORDER BY [ZipCode] [ASC];

    I am trying to list the zipcodes by ascending order then by customer name alphabetically. Thanks again!

  • ORDER BY ZipCode, CustomerName

    ORDER BY is in ascending order unless you specify otherwise

    ORDER BY CustomerName DESC

  • the WHERE clause is used to filter out data. If you just need all the zip codes, in order, you just need

    SELECT ZipCode
    FROM Address
    ORDER BY ZipCode, CustomerName;

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Note you don't have to supply a WHERE clause. WHERE is effectively used to filter your results; so if you don't include one, your result set will return all the relevant results.

    So, for example:
    --Returns all names from the Customer table, ordered by their name ASCENDING (as sort order is not specified for [name]).
    SELECT C.[name]
    FROM Customer C
    ORDER BY C.[name];

    --Only returns Customer names from the Customer table who shop at the store Tesco, ordered by their Last Shop Date DESCENDING (most recent date at top of the result set).
    SELECT C.[name]
    FROM Customer C
    WHERE C.Store = 'Tesco'
    ORDER BY C.LastShopDate DESC;

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply