Home » SQL & PL/SQL » SQL & PL/SQL » iterate the select query
iterate the select query [message #359827] Tue, 18 November 2008 05:24 Go to next message
shaksing
Messages: 115
Registered: November 2008
Senior Member
How to select the first record of a table ?

After selecting the first record from table1 i need to put the details in another column table2 in a iterative manner.

What can do for this ?
Re: iterate the select query [message #359828 is a reply to message #359827] Tue, 18 November 2008 05:27 Go to previous messageGo to next message
joicejohn
Messages: 327
Registered: March 2008
Location: India
Senior Member
@shaksing

I know this question will be in the mind of anyone who sees your post:

Define "first record of your table".


Regards,
Jo

[Updated on: Tue, 18 November 2008 05:27]

Report message to a moderator

Re: iterate the select query [message #359831 is a reply to message #359827] Tue, 18 November 2008 05:36 Go to previous messageGo to next message
shaksing
Messages: 115
Registered: November 2008
Senior Member
table1(field1,field2,field3) , where field is in numbers from 1-20, so field2 and field3 corresponding to field1,and in this case 1 (field1). Then i need to iterate on table1 and need to put values in table2 according to that.
Re: iterate the select query [message #359836 is a reply to message #359827] Tue, 18 November 2008 05:50 Go to previous messageGo to next message
Michel Cadot
Messages: 64117
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
You don't need any iteration, use a join.

Regards
Michel
Re: iterate the select query [message #359837 is a reply to message #359831] Tue, 18 November 2008 05:50 Go to previous messageGo to next message
pablolee
Messages: 2834
Registered: May 2007
Location: Scotland
Senior Member
This post makes little or no sense. Please post a test case as per the Orafaq Posting guidelines
Re: iterate the select query [message #359838 is a reply to message #359831] Tue, 18 November 2008 05:51 Go to previous messageGo to next message
joicejohn
Messages: 327
Registered: March 2008
Location: India
Senior Member
@shaksing,

Still I am not able to understand your requirement properly. Please post a test case with Create Table statements for the necessary tables and Insert statemenst (for some dummy records). based on that post your desired results along with whatever queries you have tried so far.

Before all that I will advice you to first read OraFAQ Forum Guide so that you will follow the forum guidelines on "How To Format Your Post"?

Regards,
Jo
Re: iterate the select query [message #359841 is a reply to message #359827] Tue, 18 November 2008 05:55 Go to previous messageGo to next message
shaksing
Messages: 115
Registered: November 2008
Senior Member
I will go through the link and will try to post my future messages as mentioned.
Re: iterate the select query [message #359869 is a reply to message #359827] Tue, 18 November 2008 06:46 Go to previous messageGo to next message
mail2das.ashok
Messages: 10
Registered: May 2008
Junior Member
select <column_names>
from <table_name>
group by <rownum,column_names>
where rownum=1;
Re: iterate the select query [message #359872 is a reply to message #359869] Tue, 18 November 2008 06:54 Go to previous messageGo to next message
S.Rajaram
Messages: 1027
Registered: October 2006
Location: United Kingdom
Senior Member
Quote:

select <column_names>
from <table_name>
group by <rownum,column_names>
where rownum=1;


I am impressed. Have you tested this script by any chance ?

Regards

Raj
Re: iterate the select query [message #359877 is a reply to message #359872] Tue, 18 November 2008 07:37 Go to previous messageGo to next message
mail2das.ashok
Messages: 10
Registered: May 2008
Junior Member
why u have any doubt regarding the same?

The same query will return the 1st record of the table
Re: iterate the select query [message #359879 is a reply to message #359869] Tue, 18 November 2008 07:37 Go to previous messageGo to next message
joy_division
Messages: 4640
Registered: February 2005
Location: East Coast USA
Senior Member
mail2das.ashok wrote on Tue, 18 November 2008 07:46
select <column_names>
from <table_name>
group by <rownum,column_names>
where rownum=1;


Please disregard this answer. It's not good to give such poor advice to a new user trying to learn.
Re: iterate the select query [message #359995 is a reply to message #359877] Wed, 19 November 2008 02:55 Go to previous message
Frank
Messages: 7880
Registered: March 2000
Senior Member
mail2das.ashok wrote on Tue, 18 November 2008 14:37
why u have any doubt regarding the same?

The same query will return the 1st record of the table

Why do you think you need a group by over a set of unique columns?
Do you think that group by (always) does a sort? That is WRONG.
Sorting can only be done by using ORDER BY.




Yes, I know there are some exceptions, but these are not worth mentioning in a topic where a newbie asks how to do this.
Previous Topic: Bulk INsert
Next Topic: ORA-06552: PL/SQL: Statement ignored ORA-06553: PLS-382: expression is of wrong type
Goto Forum:
  


Current Time: Tue Dec 06 04:30:31 CST 2016

Total time taken to generate the page: 0.12629 seconds