Click here to Skip to main content
15,896,448 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello friends,

I want to show records based on the records added in the table in descending order.

Problem: Table does not have primary key

The table has duplicate data, i also want to get DISTINCT records

I have done following
SQL
SELECT OpportunityName, CGN.*
FROM FWB_SFAccountAndContractGroupName CGN
INNER JOIN dbo.FWB_ufn_GetOpportunity(8047) OPP
ON CGN.OpportunityID = OPP.OpportunityID


CGN is the table which we want to refer

How is it possible?

Thanks in advance.

[edit]SHOUTING removed - Prasad_Kulkarni[/edit]
Posted
Updated 15-May-12 1:08am
v2
Comments
Prasad_Kulkarni 15-May-12 7:08am    
DON'S Shout, using all capitals considered as shouting on web, and using all small letters considered as childish. Use proper capitalization always.
dhage.prashant01 15-May-12 7:21am    
sorry for that =)
Prasad_Kulkarni 15-May-12 7:26am    
That's okay.

Use ORDER BY[^] Clause.

SQL
SELECT
    OpportunityName, CGN.*
FROM
    FWB_SFAccountAndContractGroupName CGN INNER JOIN dbo.FWB_ufn_GetOpportunity(8047) OPP ON
        CGN.OpportunityID = OPP.OpportunityID
ORDER BY
    CGN.COLUMN_NAME DESC



Or am I missing something???
 
Share this answer
 
v3
Comments
Prasad_Kulkarni 15-May-12 7:20am    
+5! :)
dhage.prashant01 15-May-12 7:20am    
CGN does not have primary key
Records are duplicated
In simple , I want to show the data in grid with the latest record at the top followed by next least latest and so on.
Try this:
SQL
SELECT OpportunityName, CGN.*
FROM FWB_SFAccountAndContractGroupName CGN 
INNER JOIN dbo.FWB_ufn_GetOpportunity(8047) OPP 
ON CGN.OpportunityID = OPP.OpportunityID
ORDER BY CGN.COLUMN_NAME desc
 
Share this answer
 
Comments
Manas Bhardwaj 15-May-12 7:12am    
We thing alike (in terms of namings...COLUMN_NAME) :)
5+
Prasad_Kulkarni 15-May-12 7:19am    
:) Thank You!
dhage.prashant01 15-May-12 7:21am    
CGN does not have primary key Records are duplicated In simple , I want to show the data in grid with the latest record at the top followed by next least latest and so on.
Prasad_Kulkarni 15-May-12 7:25am    
Okay tell me have you used date column in your table,
if yes then use order by CGN.date desc and use DISTINCT keyword if you don't want duplicate records.
dhage.prashant01 15-May-12 7:31am    
It has
OppID(varchar),
ContractGrpCode(varchar),
CGVCID(int)

sorting on this columns, does not give the required result

Do I require to add a column to the table to hold record number??
But I want to avoid adding column

any other solution?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900