Friday, March 23, 2012

Is their a way to say give me the second or third row from the tab

Is their a way to say give me the second or third row from the table
I have a table as
FirstName
LastName
Payment
I want to say give me the 2nd row from the table where FirstName ="Samay"
Is this possible
Please advice
Thanks
Please
AdviceWhat does "2nd row" mean? Ordered by what? Can you provide sample data and
desired results?
http://www.aspfaq.com/
(Reverse address to reply.)
"KritiVerma@.hotmail.com" <KritiVermahotmailcom@.discussions.microsoft.com>
wrote in message news:B9BFE8FE-C4B1-4C58-BB27-024D25066276@.microsoft.com...
> Is their a way to say give me the second or third row from the table
> I have a table as
> FirstName
> LastName
> Payment
> I want to say give me the 2nd row from the table where FirstName ="Samay"
> Is this possible
> Please advice
> Thanks
>
>
> Please
> Advice|||No, because tables don't have any logical ordering so there is no such thing
as an inherent "first", "second" or Nth row. Your question is only
meaningful if you have value(s) in some other column(s) that define which
row comes first, second or Nth.
David Portas
SQL Server MVP
--|||There is no row number on SQL Server tables. I assume you want the second
record when ordering your result set by FirstName, and LastName. If that is
the case you can do something like this to get the second one.
select top 1 * from
(select top 2 * from yourtable
where FirstName = 'Samay'
order by FirstName, LastName desc) a
order by FirstName, LastName asc
----
----
--
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"KritiVerma@.hotmail.com" <KritiVermahotmailcom@.discussions.microsoft.com>
wrote in message news:B9BFE8FE-C4B1-4C58-BB27-024D25066276@.microsoft.com...
> Is their a way to say give me the second or third row from the table
> I have a table as
> FirstName
> LastName
> Payment
> I want to say give me the 2nd row from the table where FirstName ="Samay"
> Is this possible
> Please advice
> Thanks
>
>
> Please
> Advice|||I see you have an ID column you might want to order by, so you could do the
following:
select top 1 * from
(select top 2 * from yourtable
where FirstName = 'Samay'
order by ID desc) a
order by ID asc
----
----
--
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Gregory A. Larsen" <greg.larsen@.netzero.com> wrote in message
news:ekfZs0BaEHA.3012@.tk2msftngp13.phx.gbl...
> There is no row number on SQL Server tables. I assume you want the second
> record when ordering your result set by FirstName, and LastName. If that
is
> the case you can do something like this to get the second one.
> select top 1 * from
> (select top 2 * from yourtable
> where FirstName = 'Samay'
> order by FirstName, LastName desc) a
> order by FirstName, LastName asc
>
> --
> ----
--
> ----
--
> --
> Need SQL Server Examples check out my website at
> http://www.geocities.com/sqlserverexamples
> "KritiVerma@.hotmail.com" <KritiVermahotmailcom@.discussions.microsoft.com>
> wrote in message
news:B9BFE8FE-C4B1-4C58-BB27-024D25066276@.microsoft.com...
="Samay"[vbcol=seagreen]
>

No comments:

Post a Comment