Click here to Skip to main content
15,036,891 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Create Table LocationInfo
(
Id identity(1,1) Primary key int,
Name Nvarchar(50) not null,
Location Nvarchar(50) not null,
Image Nvarchar(50) Not null,
IsValid Bit
)

What I have tried:

How to select count(id),one image,one name from Table Name where Is Valid=1 Group by location ?

I tried but i didnt get exact output what i think,so can u please tell me how to write query?
Posted
Updated 13-Jul-17 23:34pm

1 solution

What image do you want? GROUP BY is about aggregating information, not selecting a specific row. This may help to explain it: SQL GROUP By and the "Column 'name' is invalid in the select list because..." error[^]

You want a count of IDs, we get that - but to get that count, you can't get individual row information as well.
Probably, you are trying to do two tasks at the same time - and to do that, you would need to do two SELECT statements, each to collect one row, and combine them to produce the result you want - but we can't do that for you because we have no idea which image and which name you are looking for - and neither (I suspect) do you!
   
Comments
Member 13309684 14-Jul-17 5:34am
   
Image Means ImagePath,its also like a name

i want Name,Imagapath,Count(ID) from table Group By location

I tried:
Select Location,Counnt(ID),ImagePath,Name from TableName
Group By Location,Imagepath,Name

but i didnt get exact o/p what i expected?
OriginalGriff 14-Jul-17 6:12am
   
Read what I said ... then follow the link and read that as well ...

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