Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
karthikMCA
Starting Member
9 Posts |
Posted - 2010-01-13 : 05:51:03
|
Hi, I am using three tables usermgmt,countrymgmt and userpremiummgmtusermgmt tables contains following valuesuserid username email countryid status deleted 1 karthik kart@yahoo.com 1 1 0 2 kotti kotti@yahoo.com 2 1 0 3 raj raj@yahoo.com 3 1 0 4 kumar kumar@yahoo.com 1 1 0 countrymgmt tables contains following valuescountryid cname 1 India 2 Pakistan 3 srilangauserpremiummgmt tables contains following values premiumid userid paymentstatus creationtime 1 1 Active Jan 1 2010 2 1 Failed Jan 2 2010 3 1 Active Jan 3 2010 4 2 Active Jan 4 2010 5 2 Failed Jan 5 2010 6 3 Failed Jan 6 2010 7 3 Active Jan 7 2010 here we select recent premiumid for particular useridI need following valuesuserid name email paymentstatus country 1 karthik kart@yahoo.com Active India 2 kotti kotti@yahoo.com Failed Pakistan 3 raj raj@yahoo.com Active Srilanka 4 kumar kumar@yahoo.com null India I need following values based on paymentstatus is active userid name email paymentstatus country 1 karthik kart@yahoo.com Active India 3 raj raj@yahoo.com Active Srilanka I need following values based on paymentstatus is Failed userid name email paymentstatus country 2 kotti kotti@yahoo.com Active PakistanThanks in Advance |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-13 : 05:56:47
|
[code]select u.userid, u.username,u.email,p.paymentstatus,c.country from usermgmnt ujoin countrymgmnt con c.countryid=u.countryidjoin userpremiummgmnt pon p.userid=u.useridjoin (select userid,max(creationtime) as latest from userpremiummgmnt group by userid)p1on p1.userid=p.useridand p1.latest=p.creationtimewhere p.paymentstatus = @statuspass @status as active,failed etc to get relevant records[/code] |
|
|
karthikMCA
Starting Member
9 Posts |
Posted - 2010-01-13 : 06:22:57
|
Hi, Thanks for your reply. I tried to use this query it gives following resultuserid name email paymentstatus country1 karthik kart@yahoo.com Active India3 raj raj@yahoo.com Active Srilankaalso i used where condition for status=1 and deleted=0it givesuserid name email paymentstatus country3 raj raj@yahoo.com Active SrilankaThanks in Advance. |
|
|
|
|
|