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 > How to write the record number on a separate field

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-10-10, 03:59
telmessos telmessos is offline
Registered User
 
Join Date: Jan 2010
Posts: 25
How to write the record number on a separate field

Hi all,

I have table with some multiple records for each member. I need to write x th record from the same memberID on a separate field.

Let's say I have the fields of recID and memberID on the database. After my query a third field must be added and it should look like below:
Code:
Code:
Code:
recID      memberID     qnumber
1            1245         1
2            1245         2
3            1245         3
4            1530         1
5            1530         2

So basicly I have to write x th record number of each member ID. I hope I could explain it.

Thanks
telmessos
Reply With Quote
  #2 (permalink)  
Old 02-10-10, 08:00
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,517
I think this will work:
Code:
select recID, memberID, 
       (select count(*) from MyTable t2 
       where t2.memberID=t1.memberID and t2.recID <= t1.recID ) as qnumber
from   MyTable t1
order by recID, memberID
Reply With Quote
  #3 (permalink)  
Old 02-11-10, 10:04
telmessos telmessos is offline
Registered User
 
Join Date: Jan 2010
Posts: 25
Thanks mike,

I integrated the query you gave to me to my existing tables.

but at the following section I had a problem.

where t2.memberID=t1.memberID and t2.recID <= t1.recID

basicly I changed the "t2.recID <= t1.recID" section to "t2.islemtarihi <= t1.islemtarihi" which is the recording date and it works perfectly but on the records which has the same date it repeats the same number like:
Code:
1
2
2
4
to prevent the repeats, I need to keep the islemtarihi order, plus add a recID section. So basicly it will check the islemtarihi first in the order if the islemtarihi is same date, then it will use smaller recID.

Is this possible?

I will be glad if you could help.

Thanks
telmessos

Last edited by telmessos; 02-11-10 at 10:49.
Reply With Quote
  #4 (permalink)  
Old 02-15-10, 10:05
telmessos telmessos is offline
Registered User
 
Join Date: Jan 2010
Posts: 25
no other people can help me ?
Reply With Quote
Reply

Thread Tools
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