New to SQL, easy question

  • Hello, I apologize for the question but I just can't seem to get the outcome. I'm trying to have the LastName Value in the Professor table in alphabetical order.

    Here is what I have so far:

    SELECT Professor.LastName, Professor.FirstName, Department.DeptName, * from Professor order by LastName asc;

    From Department INNER JOIN Professor ON Department.DeptCode = Professor.DeptCode

    Where (((Department.DeptName)="Marketing"))

  • Kindly post your question properly . But as per my understanding below query should work

    SELECT Professor.LastName, Professor.FirstName, Department.DeptName, *

    From Department INNER JOIN Professor ON Department.DeptCode = Professor.DeptCode

    Where (((Department.DeptName)=”Marketing”))

    order by Professor.LastName asc

    Saravanan

  • You probably want to remove the ", *" too, list only the columns you require.

    ...

  • A little bit of formatting, aliases and proper syntax you query might look like this.

    SELECT p.LastName
    , p.FirstName
    , d.DeptName
    from Professor p
    INNER JOIN Department d ON d.DeptCode = p.DeptCode
    Where d.DeptName = 'Marketing'
    order by p.LastName asc;

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Hello, I apologize for the question but I just can’t seem to get the outcome. I’m trying to have the LastName Value in the Professor table in alphabetical order. Sarkari Result  Pnr Status Showbox Here is what I have so far:

    SELECT Professor.LastName, Professor.FirstName, Department.DeptName, * from Professor order by LastName asc;

    From Department INNER JOIN Professor ON Department.DeptCode = Professor.DeptCode

    Where (((Department.DeptName)=”Marketing”))

     

    Okk

  • You must add an ORDER BY clause to the query to get the rows to be in a specific order. But, the ORDER BY must also be in a specific order for SQL to accept it [at least with most dbmses], like below. ORDER BY must come after the WHERE clause, for example:

    SELECT Professor.LastName, Professor.FirstName, Department.DeptName, *

    From Department INNER JOIN Professor ON Department.DeptCode = Professor.DeptCode

    Where (((Department.DeptName)=”Marketing”))

    order by LastName asc;

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • If you folks look at the followup message with the stupid links in them, this OP is nothing more than a spammer.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I didn't, and wouldn't, look at the links. But thanks for the heads-up on this poster.

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • To be sure, I'd never recommend clicking on such links in such a post (and I know you didn't so just saying it out loud for others that may read this) but I did look at their names and where they were pointing.  Even if their display names had something to do with SQL Server, I'd still not blindly click on them.  I'd still look at where they're pointing, first.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

Viewing 11 posts - 1 through 10 (of 10 total)

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