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!

Show last record

Status
Not open for further replies.

FB1

Instructor
May 31, 2005
69
GB
Hi Everyone

A newbie to MySQL

Need to pull data from a table that shows the last entry
the data is as follows

oid fk_oid NVPDAT NVp1 NVp2 NVp3
310 3456 '2009-01-05 00:00:00' RA1 RA2 RA3
309 3456 '2010-05-31 00:00:00' CF4 CF5 CF6
308 3456 '2010-11-19 00:00:00' JK5 JK6 JK7

FK_OID is the name of the person, OID is a unique line id, the lowest number in the column shows the latest entry.

I will need to join this to the person table via FK_OID

I will use the sql view or create a Crystal command so I can create a report on the details.

there will be 5 other tables I will need to add into the report, that work the same way as above table.

Any ideas

Ralph
 
ORDER BY OID LIMIT 1 will give you the lowest value but what happens when OID reaches zero?

For a unique ID number you would usually use an auto_increment column.

Keith
 
Thank you for your help.

the number stays the same except when a new record for that person is added, then the new record has the lowest number.

I have looked at the db and not all person have the number starting at 308, some start at 1 and other start at 10, they all do the same thing, i.e. when a new detail is added this takes over the previous number and then moves everything up, Why cannot tell you.

Giving me a head ache at the moment
Any Ideas
 
I am trying to get the last date entry for each user

the users are fk_oid

Select
distinct p_hdpresc.oid,
p_hdpresc.fk_oid,
p_hdpresc.HWDATE as date1,
p_hdpresc.HWMINS dialysis_time,
p_hdpresc.HWDRYW as target_weight,
p_hdpresc.HWBFLA as blood_flow,
p_hdpresc.HWBMM,
BM.codetext as BM_monitoring,
p_hdpresc.HWNEED,
nee.codetext as needles,
p_hdpresc.HWNTYA,
art.codetext as art_needle,
p_hdpresc.HWNTYV,
ven.codetext as Ven_needle,
p_hdpresc.HWNTYS,
sin.codetext as single_needle,
p_hdpresc.HWCL1 as cathheter_lock1,
p_hdpresc.HWCL2 as cathheter_lock2 ,
p_hdpresc.HWCL3 as cathheter_lock3,
p_hdpresc.HWLOCK,
loc.codetext as lock_type,
p_hdpresc.HWSOLN,
csol.codetext as cleaning_Solution,
p_hdpresc.HWS1 ,
p_hdpresc.HWS2,
p_hdpresc.HWS3,
p_hdpresc.HWCUFF as bp_cuff,
p_hdpresc.HWDTYP,
dia.codetext as Dialyser,
p_hdpresc.HWCURT,
cthe.codetext as Current_therapy,
p_hdpresc.HWDFLU,
con.codetext as concentrate,
p_hdpresc.HWNA as sodium_setting,
p_hdpresc.HWHCO3 as bicarb_setting,
p_hdpresc.HWTEMP as Dialysate_Temp,
p_hdpresc.HWDFLO as Dialysate_Flow_rate,
p_hdpresc.HWHEPM as Rate_per_hout,
p_hdpresc.HWSTIM as stop_time,
p_hdpresc.HWOTH2 as notes,
p_hdpresc.HWHEPL as Bolus,
p_hdpresc.HWOACC,
p_hdpresc.HWOACC2,
p_hdpresc.HWUFNA as uf_sodium_profile,
p_hdpresc.HWMACTYPE as Machine_type,
1std.codetext as Shift1, 2std.codetext as Shift2, 3std.codetext as Shift3,
acc1.codetext as Access1, acc2.codetext as Access2 FROM renaltest.p_hdpresc
left join codes as 1std on 1std.proid = p_hdpresc.hws1
left join codes as 2std on 2std.proid = p_hdpresc.hws2
left join codes as 3std on 3std.proid = p_hdpresc.hws3
left join codes as acc1 on acc1.proid = p_hdpresc.hwoacc
left join codes as acc2 on acc2.proid = p_hdpresc.hwoacc2
left join codes as BM on BM.proid = p_hdpresc.HWBMM
left join codes as nee on nee.proid = p_hdpresc.HWNEED

left join codes as art on art.proid = p_hdpresc.HWNTYA
left join codes as ven on ven.proid = p_hdpresc.HWNTYv
left join codes as sin on sin.proid = p_hdpresc.HWNTYS
left join codes as dia on dia.proid = p_hdpresc.HWDTYP
left join codes as con on con.proid = p_hdpresc.HWDFLU
left join codes as loc on loc.proid = p_hdpresc.HWLOCK
left join codes as csol on csol.proid = p_hdpresc.HWSOLN
left join codes as cthe on cthe.proid = p_hdpresc.HWCURT
group by p_hdpresc.fk_oid, (p_hdpresc.hwdate)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top