Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

View with most common value AS Column_Name

Status
Not open for further replies.

deanbri75

Technical User
Jan 6, 2004
26
US
I have a table with a column containing a term code (200810, 200820, 200730, etc).

I want to create a view (we'll call it View2) with a column value with the most common term code for every record in the View2.

I can get the value I want by using the following select query in a separate View (called View1)

Code:
SELECT     TOP 1 SLBRMAP_FROM_TERM
FROM         dbo.APPLICATION
GROUP BY SLBRMAP_FROM_TERM
ORDER BY COUNT(*) DESC

My problem is how to incorporate this value into the column of my view.

I'd like to use that select query AS Column_Name in my view.

I can do something like this in View2 just referencing the results of View1. It works but seems like there is a better way.
Code:
SELECT     dbo.View1.SLBRMAP_FROM_TERM, dbo.APPLICATION.AREA_PREF1, dbo.APPLICATION.AREA_PREF2, dbo.APPLICATION.AREA_PREF3
FROM         dbo.APPLICATION CROSS JOIN
                      dbo.View1
thanks,
brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top