View previous topic :: View next topic
|
Author |
Message |
Laxminarsimharao
New User
Joined: 08 May 2007 Posts: 26 Location: hyderabad
|
|
|
|
How can we retrive first row in a table using SQL query ?
i.e. top row in a table. |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
Back to top |
|
|
vasanthkumarhb
Active User
Joined: 06 Sep 2007 Posts: 275 Location: Bang,iflex
|
|
|
|
Hi,
Please try this Query below and let me know
Code: |
SELECT * FROM TABLE FETCH FIRST 1 ROWS ONLY; |
Regard's
Vasanth.........
"Never Give Up Until U Succeed" |
|
Back to top |
|
|
Laxminarsimharao
New User
Joined: 08 May 2007 Posts: 26 Location: hyderabad
|
|
|
|
Thanks it's working. |
|
Back to top |
|
|
venkatm99
New User
Joined: 01 Jun 2006 Posts: 23 Location: Sinagpore
|
|
|
|
HI
Code:
SELECT * FROM TABLE FETCH FIRST 1 ROWS ONLY;
Can the above query works in the program as singleton select ??
or
Cursor is needed?
cheers
venkat |
|
Back to top |
|
|
Laxminarsimharao
New User
Joined: 08 May 2007 Posts: 26 Location: hyderabad
|
|
|
|
Cursor is required for that one. |
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
Hi Laxminarsimharao,
Would you please tell me why u r require CURSOR when u r fetching single row only.
Please go throgh the manual
Venkat,
No cursor is not required becoz that query always resultant a single row. |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
In addition to Ekta's post -
You can always DECLARE cursor to make the program bit complex (you know show off). |
|
Back to top |
|
|
revel
Active User
Joined: 05 Apr 2005 Posts: 135 Location: Bangalore/Chennai-INDIA
|
|
|
|
Hi Murali,
What did you mean?
Could you please elaborate... |
|
Back to top |
|
|
vasanthkumarhb
Active User
Joined: 06 Sep 2007 Posts: 275 Location: Bang,iflex
|
|
|
|
Murali,
Then, why cursor is needed could you pls clear your answer?
__________________
Regard's
Vasanth........
"Never Give Up Until U Succeed". |
|
Back to top |
|
|
Bitneuker
CICS Moderator
Joined: 07 Nov 2005 Posts: 1104 Location: The Netherlands at Hole 19
|
|
|
|
murmohk1 wrote: |
In addition to Ekta's post -
You can always DECLARE cursor to make the program bit complex (you know show off). |
We should not post like this; it confuses |
|
Back to top |
|
|
Bitneuker
CICS Moderator
Joined: 07 Nov 2005 Posts: 1104 Location: The Netherlands at Hole 19
|
|
|
|
The requirement has been answered and works. Read the answers. |
|
Back to top |
|
|
vasanthkumarhb
Active User
Joined: 06 Sep 2007 Posts: 275 Location: Bang,iflex
|
|
|
|
George,
Link provided by you are helpfull, thank you for the links.
__________________
Regard's
Vasanth..........
"Never Give Up Untill U Succeed" |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
vasanthkumarhb wrote: |
Code: |
SELECT * FROM TABLE FETCH FIRST 1 ROWS ONLY; |
|
Without ORDER BY clause this query is bit garbage, it'll select just any row..how do you decide what is & first- what is last-line ? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
Without ORDER BY clause this query is bit garbage, it'll select just any row..how do you decide what is & first- what is last-line ? |
that' something that makes me wonder on the real quality of application developed by some sites
SO MANY DATA SETS WITH RECORD POSITION DEPENDENCY
.. I need to extract the first record
.. I need the last record
..
.. copy everything except the 75th record
.. add more of this kind
it makes me think that' s mostly homework, or as an alternative
the worst designed applications in ... choose a big enough domain |
|
Back to top |
|
|
Bitneuker
CICS Moderator
Joined: 07 Nov 2005 Posts: 1104 Location: The Netherlands at Hole 19
|
|
|
|
Laxminarsimharao wrote: |
How can we retrive first row in a table using SQL query ?
i.e. top row in a table. |
is his requirement.......
Quote: |
Posted: Wed Nov 07, 2007 2:14 pm Post subject:
--------------------------------------------------------------------------------
Thanks it's working.
|
is his reaction after implementing the solution.
I wonder why the topic is still discussed |
|
Back to top |
|
|
stodolas
Active Member
Joined: 13 Jun 2007 Posts: 632 Location: Wisconsin
|
|
|
|
Because the solution will provide inconsistent results unless an order by is specified. |
|
Back to top |
|
|
vasanthkumarhb
Active User
Joined: 06 Sep 2007 Posts: 275 Location: Bang,iflex
|
|
|
|
Hi Anuj,
Try this query, it works good for you too, the query syntax is correct pls check it and let me know.
Regard's
Vasanth......... |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Try this query, it works good for you too, the query syntax is correct pls check it and let me know |
I see no query to try. . .
Keep in mind there is no such thing as a "first row". . . The posted query will return a row, but there is nothing "first" about it. . . It is just a row, like all of the others, unless some order is specified. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Hi Vasanth,
Ah...sorry to join the party bit late..well I hope you got enough suggestion, one more from my side...
Try the same query you are suggesting..with ORDER BY clause & without it..do you see some difference in the results? |
|
Back to top |
|
|
|