Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert into table in specific place 2

Status
Not open for further replies.

reidadam

Programmer
Sep 27, 2001
1
US
Is it possible to insert data into a specific row?

eg. insert 6 at row 8

Cheers,

Adam
 
No. The whole underlying theory of relational databases is that location of data is irrelevant - it's the contents of the data that count. Consequently, it really doesn't matter which row you're inserting into - you can select, update, and delete by providing information about what you are looking for.
 
ok, in that case it is possible to retrieve records in a specific order other than ASC or DESC?

eg, display 1,4,5,2,3??

Cheers,

Adam
 
No way that I'm aware of (well, OK, it can be done but it's ugly:
SELECT val FROM my_table WHERE val=1
UNION ALL
SELECT val FROM my_table WHERE val=4
.
.
. )

If you need to display in the order you gave, then you would probably have to create a separate column that, when sorted, results in the display you gave. For instance, your table might look like:

sort_col display_col
1 1
4 2
5 3
2 4
3 5



Then, the query
SELECT display_col FROM my_table ORDER BY sort_col
would give you the desired results.
 
A case statement could be used to create a temp file for the expressed purpose of sorting.

Select
table1.field1, table1.field2, (CASE table1.field1 when '1' then '1' when '2' then '4' when '3' then '5' when '4' then '2' when '5' then '3' END)
from
table1
order by 3;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top