| Author |
Topic |
|
nasman
Starting Member
15 Posts |
Posted - 2011-12-19 : 23:17:09
|
| my table looks like this col1 col2 col3row1 a b crow2 a b drow3 d e frow4 g h icol1 transaction numbercol2 account idcol3 represent transaction timethe problem is row 1 and 2 is a duplicate account with different transaction time, i want to select only distinct col1 and 2 regardless of the col3. |
|
|
nasman
Starting Member
15 Posts |
Posted - 2011-12-19 : 23:19:30
|
| the result should becol1 col2a bd eg h |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-20 : 00:08:29
|
| [code]SELECT DISTINCT TransactionNumber,AccountIDFROM YourTable[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
nasman
Starting Member
15 Posts |
Posted - 2011-12-20 : 01:02:31
|
| if i do that the result will be like thisd eg hi tried this query but still doesnt workselect t1.col1, t1.col2from table1 t1where col2 = (select max(col3) from table1 t2 where t1.col1 = t2.col2) |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-12-20 : 01:12:17
|
quote: Originally posted by nasman if i do that the result will be like thisd eg hi tried this query but still doesnt workselect t1.col1, t1.col2from table1 t1where col2 = (select max(col3) from table1 t2 where t1.col1 = t2.col2)
Did you try the query Visakh posted ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
nasman
Starting Member
15 Posts |
Posted - 2011-12-20 : 02:16:11
|
| @khatanyes tried it already,the result was like thiscol1 col2d eg h-----------what my desired result isa bd eg h-----------the situation:transaction 'a b' has a duplicate but the duplicate has a different transaction time. i just want to select distinct 'a b' regardless of its transaction time |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-20 : 03:21:18
|
quote: Originally posted by nasman @khatanyes tried it already,the result was like thiscol1 col2d eg h-----------what my desired result isa bd eg h-----------the situation:transaction 'a b' has a duplicate but the duplicate has a different transaction time. i just want to select distinct 'a b' regardless of its transaction time
hmm...then i'm sure there're some other things related to this which you've not yet specified to ustaking DISTINCT wont cause any rows to disappearas per you posted sample data, my query should give youa bd eg h------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
nasman
Starting Member
15 Posts |
Posted - 2011-12-20 : 03:44:28
|
| i just simplified it (the sample table), sorry if it became ambiguous here is my code without distinctselect t1.corp_id, t1.branch_id, t2.trans_date_time, t2.trans_no, t2.sale_amt, t2.points t2.account_idfrom branch t1, transact t2where t1.branch_id = t2.branch_idand t2.trans_date = '2010-05-23'order by t2.account_id desc |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-20 : 04:26:32
|
| hmm... what does the other fields contain? and is the relationship between tables one to one? best thing would be to post some data from the tables (about 5 rows each) and then provide sample output you want------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|