If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > select fields and create temp field.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-25-05, 04:42
popskie popskie is offline
Registered User
 
Join Date: Oct 2004
Location: In cousin's house
Posts: 303
select fields and create temp field.

hi,
Sory, I dont knew how to start but anyway. my problem is somthing like dis.
I have a table and a field and im using mysql 5.0.3.
Code:
table1
field1 field2
aaaa test1
bbbb test3
cccc test4
mmmm test7
lllll test8
I want a result like dis.
Code:
field1 field2 ,tempfield
aaaa test1 1
bbbb test3 2
cccc test4 3
mmmm test7 4
lllll test8 5
thanks ,
Popskie
Reply With Quote
  #2 (permalink)  
Old 10-25-05, 06:12
felixg felixg is offline
Registered User
 
Join Date: Apr 2005
Location: Lier, Belgium
Posts: 122
Please be more precise:

1) what is the sort type and order on which column
2) what should happen with ties (i.e. when two or more values are the same w.r.t. the sort type and order)

--
felix
Reply With Quote
  #3 (permalink)  
Old 10-25-05, 20:25
popskie popskie is offline
Registered User
 
Join Date: Oct 2004
Location: In cousin's house
Posts: 303
Just in any order in my sample table has just only 2 fields. Pls look at my query.

select *,_temp_incrementfield from tablename

but i dont knw how to increment in select statement. Sory for my english.
Reply With Quote
  #4 (permalink)  
Old 10-26-05, 02:46
felixg felixg is offline
Registered User
 
Join Date: Apr 2005
Location: Lier, Belgium
Posts: 122
Quote:
Originally Posted by popskie
Just in any order in my sample table has just only 2 fields. Pls look at my query.
select *,_temp_incrementfield from tablename
I meant you need an ORDER BY. E.g.
Code:
SET @rank := 0;
SELECT 
    field1, field2, @rank := @rank+1 
FROM tablename
ORDER BY field2;
--
felix
Reply With Quote
  #5 (permalink)  
Old 10-26-05, 04:09
popskie popskie is offline
Registered User
 
Join Date: Oct 2004
Location: In cousin's house
Posts: 303
thats it , nice shoot . Thanks for the rep.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On