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.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Sql Select Query

Author  Topic 

amuluri
Starting Member

8 Posts

Posted - 2007-11-27 : 02:09:33
hi am raj!
am a asp , sql server 2000 programmer

i need a sql query to select unique rows based on noofcards,versionno,id here am giving the database
-------------------------------------------
id email ccno vno nc
-------------------------------------------
41 b@r.com f 2465 1 1
41 b@r.com f 9898 1 3
41 b@r.com a 9898 1 2
41 b@r.com f 2465 2 1
41 b@r.com e 6226 2 2
41 b@r.com s 2465 3 1
------------------------------------------
ccno = creditcardno
vno = versionno
no = noofcard

the o/p i should get is
-------------------------------------------
id email ccno vno nc
-------------------------------------------
41 b@r.com f 3554 1 3
41 b@r.com e 6226 2 2
41 b@r.com s 2465 3 1
------------------------------------------

i tryed this query
select * from creditcardinfo where versionno =(select max(versionno) from creditcardinfo where id =41)

but am getting only one row with the maxversionno

41 b@r.com s 2465 3 1

so, pleas help me in getting the row i 've specified above.

any help will be appreciated.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-27 : 02:16:08
your sample data title have 5 columns but the data have 6. Please clarify.

Please post your table DDL in create table statement and sample data in insert table .. format. It will make things easier. .


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

amuluri
Starting Member

8 Posts

Posted - 2007-11-27 : 07:27:12
thanq for ur advice khtan !
here am sending a neat formated table
-------------------------------------------
id email name ccno vno nc
-------------------------------------------
41 b@r.com f 2465 1 1
41 b@r.com f 9898 1 3
41 b@r.com a 9898 1 2
41 b@r.com f 2465 2 1
41 b@r.com e 6226 2 2
41 b@r.com s 2465 3 1
------------------------------------------
and the o/p i should get is

-------------------------------------------
id email name ccno vno nc
-------------------------------------------
41 b@r.com f 3554 1 3
41 b@r.com e 6226 2 2
41 b@r.com s 2465 3 1
------------------------------------------
please help me in getting this.
thanq ones again Khtan
Go to Top of Page

amuluri
Starting Member

8 Posts

Posted - 2007-11-27 : 07:32:41
its table statement is

create table ccinfo (id int,emailid varchar(100),name varchar(100),ccno nvarchar(25),vno int,nc int)
where id,vno,nc are primarykeys

this is the insert query
insert into ccinfo values (41,'b@r.com','h','1234',1,4)

Go to Top of Page

tfountain
Constraint Violating Yak Guru

491 Posts

Posted - 2007-11-27 : 07:36:14
I think the data samples you showed are incorrect and can only assume you either (a) want to get distinct records or (b) summarize data for distinct records. Check out the BOL or Google (a) the DISTINCT keyword and/or (b) the GROUP BY clause and aggregates.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-27 : 09:17:08
[code]-------------------------------------------
id email name ccno vno nc
-------------------------------------------
41 b@r.com f 3554 1 3
41 b@r.com e 6226 2 2
41 b@r.com s 2465 3 1
------------------------------------------[/code]

can you explain how to obtain the 3554 ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -