July 28, 2018 at 9:29 am
Hi All,
I need a solution for this problem please help me
First Create table like below query
create table people (Firstname varchar(50),FamilyName varchar(50),City varchar(50))
then
insert value like Arun, Don, Chennai
insert value like Hema, Don, Chennai
insert value like Kumar, Don, Chennai
I need to display one row for above three rows for that i need a query please help me.
July 28, 2018 at 10:05 am
tvrarundeepak - Saturday, July 28, 2018 9:29 AMHi All,
I need a solution for this problem please help meFirst Create table like below query
create table people (Firstname varchar(50),FamilyName varchar(50),City varchar(50))
then
insert value like Arun, Don, Chennai
insert value like Hema, Don, Chennai
insert value like Kumar, Don, ChennaiI need to display one row for above three rows for that i need a query please help me.
Is this what you need as output
Firstname | Firstname | Firstname | FamilyName | City |
Arun | Hema | Kumar | Don | Chennai |
Saravanan
July 28, 2018 at 10:18 am
Hi Saravanan,
Output should like this
FirstName FamilyName
Arun Don
July 28, 2018 at 10:23 am
Hi,
Your output doesn't clarify the objective. How are you picking only one record from the set of three records? Is there any filter applied? In case I understood your initial question properly, you can get a comma separated list of first names for each distinct set of family name and cities by this:
SELECT STUFF((SELECT ',' + Firstname FROM dbo.people FOR XML PATH('')),1,1,' ') AS FirstName, FamilyName, City
FROM dbo.people
GROUP BY FamilyName, City
Let us know.
July 28, 2018 at 10:24 am
tvrarundeepak - Saturday, July 28, 2018 10:18 AMHi Saravanan,
Output should like this
FirstName FamilyName
Arun Don
Only you want the below as output:
FirstName FamilyName
Arun Don
Are you sure?
Saravanan
July 28, 2018 at 10:31 am
saravanatn - Saturday, July 28, 2018 10:24 AMtvrarundeepak - Saturday, July 28, 2018 10:18 AMHi Saravanan,
Output should like this
FirstName FamilyName
Arun DonOnly you want the below as output:
FirstName FamilyName
Arun DonAre you sure?
yes
July 28, 2018 at 10:32 am
tvrarundeepak - Saturday, July 28, 2018 10:31 AMsaravanatn - Saturday, July 28, 2018 10:24 AMtvrarundeepak - Saturday, July 28, 2018 10:18 AMHi Saravanan,
Output should like this
FirstName FamilyName
Arun DonOnly you want the below as output:
FirstName FamilyName
Arun DonAre you sure?
yes
like there is n number of familyname and firstname
July 28, 2018 at 10:36 am
You can simply get it by using TOP 1 like this:
SELECT TOP 1 FirstName, Familyname
FROM dbo.people
July 28, 2018 at 10:37 am
tvrarundeepak - Saturday, July 28, 2018 10:32 AMtvrarundeepak - Saturday, July 28, 2018 10:31 AMsaravanatn - Saturday, July 28, 2018 10:24 AMtvrarundeepak - Saturday, July 28, 2018 10:18 AMHi Saravanan,
Output should like this
FirstName FamilyName
Arun DonOnly you want the below as output:
FirstName FamilyName
Arun DonAre you sure?
yes
like there is n number of familyname and firstname
your explanation is not clear. Can you kindly post expected output?
Saravanan
July 28, 2018 at 10:52 am
saravanatn - Saturday, July 28, 2018 10:37 AMtvrarundeepak - Saturday, July 28, 2018 10:32 AMtvrarundeepak - Saturday, July 28, 2018 10:31 AMsaravanatn - Saturday, July 28, 2018 10:24 AMtvrarundeepak - Saturday, July 28, 2018 10:18 AMHi Saravanan,
Output should like this
FirstName FamilyName
Arun DonOnly you want the below as output:
FirstName FamilyName
Arun DonAre you sure?
yes
like there is n number of familyname and firstname
your explanation is not clear. Can you kindly post expected output?
In the below table we have three family names for example
Output should be like this
Firstname should be randomly selected for each family.
Firstname Familyname city
Mathu Don US
Peri Chennai TN
no Do ys
July 28, 2018 at 10:57 am
Hi,
You can achieve this by using the following query:
SELECT
MAX(Firstname), FamilyName, City
FROM dbo.people
GROUP BY FamilyName, City
But, it doesn't make good sense to me.
July 28, 2018 at 11:00 am
debasis.yours - Saturday, July 28, 2018 10:57 AMHi,You can achieve this by using the following query:
SELECT
MAX(Firstname), FamilyName, City
FROM dbo.people
GROUP BY FamilyName, CityBut, it doesn't make good sense to me.
Thanks for concerns
July 28, 2018 at 11:01 am
tvrarundeepak - Saturday, July 28, 2018 11:00 AMdebasis.yours - Saturday, July 28, 2018 10:57 AMHi,You can achieve this by using the following query:
SELECT
MAX(Firstname), FamilyName, City
FROM dbo.people
GROUP BY FamilyName, CityBut, it doesn't make good sense to me.
Thanks for concerns
Its working fine
July 28, 2018 at 11:13 am
tvrarundeepak - Saturday, July 28, 2018 10:52 AMsaravanatn - Saturday, July 28, 2018 10:37 AMtvrarundeepak - Saturday, July 28, 2018 10:32 AMtvrarundeepak - Saturday, July 28, 2018 10:31 AMsaravanatn - Saturday, July 28, 2018 10:24 AMtvrarundeepak - Saturday, July 28, 2018 10:18 AMHi Saravanan,
Output should like this
FirstName FamilyName
Arun DonOnly you want the below as output:
FirstName FamilyName
Arun DonAre you sure?
yes
like there is n number of familyname and firstname
your explanation is not clear. Can you kindly post expected output?
In the below table we have three family names for example
Output should be like this
Firstname should be randomly selected for each family.
Firstname Familyname city
Mathu Don US
Peri Chennai TN
no Do ys
Below query should work I think
SELECT
MAX(Firstname) over(partition by FamilyName,City order by Firstname) as Firstname,
FamilyName,City
FROM dbo.people;
----------------------------------------
SELECT
MIN(Firstname) over(partition by FamilyName,City order by Firstname) as Firstname,
FamilyName,City
FROM dbo.people;
Saravanan
July 28, 2018 at 11:20 am
saravanatn - Saturday, July 28, 2018 11:13 AMtvrarundeepak - Saturday, July 28, 2018 10:52 AMsaravanatn - Saturday, July 28, 2018 10:37 AMtvrarundeepak - Saturday, July 28, 2018 10:32 AMtvrarundeepak - Saturday, July 28, 2018 10:31 AMsaravanatn - Saturday, July 28, 2018 10:24 AMtvrarundeepak - Saturday, July 28, 2018 10:18 AMHi Saravanan,
Output should like this
FirstName FamilyName
Arun DonOnly you want the below as output:
FirstName FamilyName
Arun DonAre you sure?
yes
like there is n number of familyname and firstname
your explanation is not clear. Can you kindly post expected output?
In the below table we have three family names for example
Output should be like this
Firstname should be randomly selected for each family.
Firstname Familyname city
Mathu Don US
Peri Chennai TN
no Do ys
Below query should work I thinkSELECT
MAX(Firstname) over(partition by FamilyName,City order by Firstname) as Firstname,
FamilyName,City
FROM dbo.people;
----------------------------------------
SELECT
MIN(Firstname) over(partition by FamilyName,City order by Firstname) as Firstname,
FamilyName,City
FROM dbo.people;
ya it is working for this query
Thanks
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply