How do i select the top1 column from a table in a select statement which contains multiple columns from multiple columns

  • I am trying to get the top1 column from a table in a select statement which contains multiple columns from multiple columns,

    Basically , Below is how my query looks like

    Select col1,col2,col3,table4.col4,col5

    from table1 innerjoin table2 left join table3,left outer join table4 .

    where..............................

    here in table 4 the data is not updated but a new record is inserted when their is a update. I have to see that table4.col4 is compared with input and table4.col4 is the top1 row when i am checking dateentered desc.

    All this needs to be in sql query as prev developer has written this page in HTML

    So i am selecting only one column which shd be the top1 of that table and none others in that select statement

  • Perhaps I'm asking too much but could you provide the DDL, the DM to insert the Data and your Statement so that you may be better assisted?

    Thanks,

    WC

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • In addition to the data WC asked for, you should provide the column we need to order the values. Otherwise the TOP statement won't make that much sense...



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • Hi guys,

    I apologise for posting incomplete question, i found out the solution for it.will post here asap

  • Thank you Lutz, please accept my apology for not asking for complete information...

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Welsh Corgi (3/5/2010)


    Thank you Lutz, please accept my apology for not asking for complete information...

    No reason to apologize. That's what a forum is all about: to have more than just one person to look at a problem.

    And if someone did overlook a required information (or assumed that it would obviously be needed and therefore didn't ask for it specifically), then there will be others to expand the question. There's nothing wrong with it (especially nothing that would require to delete a post 😉 ).



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

Viewing 6 posts - 1 through 5 (of 5 total)

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