Recently, I have been coding T-SQL Stored Procedures in a SQL Server database when I ran across something which should be easy to do, but probably wasn’t, that ended up actually being easy. Specifically, I had to find the most commonly occurring item in a column in a table.
For example if I had a People table with a Name column with the values: Paul, Dave, Paul. Now, I want to find the value “Paul” because it occurs most frequently.
Obviously, my first thought was to do:
select Name, count(*)
group by Name
order by count(*) desc
which would give me 2 rows:
Then, I could add a ‘top 1’ to the select to only get:
However, this is not what I want. I don’t want the ‘2’. So, I played around with the SQL a bit and came up with:
select top 1 Name
group by Name
order by Count(*) desc
This SQL gave me exactly what I wanted: ‘Paul’
So, it actually turned out to be easy! I just wanted to share this with everybody in case you run across the same situation and need a good solution.
I am running Windows 7 and Google Chrome. Recently, I updated Chrome to the latest version, 38. After that I had nothing but problems with Chrome. New tabs wouldn’t open, pop-up windows would be blank and hang, etc.. It was so bad, that I started using Internet Explorer again!
Finally, when I had some free time I Googled a bit, I found a fix.
The fix is to set the Compatibility Mode to Windows 7. To do this, open the Properties (right-click on icon on Chrome icon on desktop), click on the Compatibility tab (see screen shot below), check the ‘Run this program in compatibility mode for:’ checkbox, select ‘Windows 7’ in the drop-down. Note: you can also works for Windows Vista, Windows XP, and many other versions.
Since making this change, I have not had any problems using Chrome.
To find out what instances of SQL Server are installed on a Windows PC:
1. Open a Command window (In Windows 7, click Start button, enter: cmd <enter> in ‘Search programs and file’ field).
2. Enter: SQLCMD – L <enter> into the command window. Note that the ‘L’ in the -L must be a capital L.
Here is an example from my PC: