sql server - Select Column if Unique in SQL -


I'm looking at a way to select only one column value if it's unique.

Example of data in the table:

  City name ----------------------- James New York 20 Charles New York 21 Tom New York 22  

Example of the output of all the queries to choose:

  city name -------- -------------- James New York 20 Charles New York 21 Tom New York 22  

But if Charles lived in London then I would not print a city Should have a default value

Example of data in the table:

  city Name the name ------------------------ James New York 20 Charles London 21 Tom New York 22  

All An example of selecting a query.

City Name ----------------------- James / 20 Charles / 21 Tom / 22 < / Ex>

I hope you can do SQL magic ...

I tried to do it with a case structure but without any success I am using SQL Server.

Use joining other cities, and mask the duplicates:

  Specific P. Choose the name, case when p2.city is not zero then zero and PIIT City ends, P.G. P. Names on the name = P. 2. Name and P on the person P2 city! = P2.city  

different creates the result of only one line for duplicate cities.

This query depends on age depending on the names given between cities, if not so, use maximum (age) and something like a group .

To provide a default value instead of null for duplicates, change then from zero to , then 'Miscellaneous' Code> (e.g.).


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -