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 |
|
royramos
Starting Member
9 Posts |
Posted - 2011-02-27 : 19:41:35
|
| Hi guys,I have problem extracting needed data with the format that i need, can anybody please help me on this, i have 2 table please see belowusertableid | name |1 | user1 |2 | user2 |3 | user3 |4 | user4 |login tableid | date | time1 | 02/28/11 | 8301 | 02/28/11 | 9001 | 02/28/11 | 17302 | 02/28/11 | 8002 | 02/28/11 | 17303 | 02/28/11 | 830maybe you guys can help me to extract data on this formatid | name | date | logintime(min)1 | user1 |02/28/11 | 8302 | user2 |02/28/11 | 8003 | user3 |02/28/11 | 8304 | user4 | null | nullthanks,-roy-roy |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2011-02-27 : 20:33:36
|
| This isn't a formatting issue. You just need to use the MIN function and and inner join between the 2 tables.JimEveryday I learn something that somebody else already knew |
 |
|
|
royramos
Starting Member
9 Posts |
Posted - 2011-02-27 : 21:48:01
|
| hi jim thanks for the reply, this is what i've done alreadyi create a separate view to extract logintime min(logintime_min)select id, date, min(time) as mintime from login group by id, datethen i try to extract data using thisselect usertable.id, usertable.name, logintime_min.mintime from usertableinner join logintime_min on usertable.id=logintime_min.id where logintime_min.date='02/28/11'problem here is other user like user4 that don't have entry in login table was not displaythanks,-roy-roy |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2011-02-27 : 23:32:12
|
| Try this :Create table #usertable( Id int, [name] varchar(50)) Create table #login(id int,[date] datetime,[time] int)Insert into #login Select 1,'02/28/11', 830 union all Select 1,'02/28/11', 900 union all Select 1,'02/28/11', 1730 union all Select 2,'02/28/11', 800 union all Select 2,'02/28/11', 1730 union all Select 3,'02/28/11', 830Insert into #usertableSelect 1,'user1' union all Select 2,'user2' union all Select 3,'user3' union all Select 4,'user4' Select ut.id, ut.[name], min([time])from #usertable ut left outer join #login lnon ut.id = ln.idand ln.[date] = '02/28/11'group by ut.id, ut.[name]You naming convention is improper. Read some document on SQL Standard so that you get better idea |
 |
|
|
royramos
Starting Member
9 Posts |
Posted - 2011-02-28 : 19:50:16
|
| Hi Pk bohra thanks it's working, i take your advised and gonna study somemore thanks-roy |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2011-02-28 : 23:02:20
|
quote: Originally posted by royramos Hi Pk bohra thanks it's working, i take your advised and gonna study somemore thanks-roy
You are welcome I am here to learn from Masters and help new bees in learning. |
 |
|
|
|
|
|
|
|