开发者

How can I select a category and the first picture associated with that category?

开发者 https://www.devze.com 2023-04-04 17:11 出处:网络
What I\'m trying to do: I want a grid of picture categories to be generated from the categories in my database. So I\'m pulling all of the categories with this SQL command.

What I'm trying to do: I want a grid of picture categories to be generated from the categories in my database. So I'm pulling all of the categories with this SQL command.

SELECT * FROM Category

But I also want a picture to show up in the listview so I tried to add this subquery to it

SELECT * FROM Category 
INNER JOIN Pictures ON Category.CategoryId = Pictures.CategoryId
(SELECT TOP 1 Pictures.PictureFilePath FROM Pictures
 WHERE Catergory.CategoryId = Pi开发者_C百科ctures.CategoryId)

When I try to test the query it tells me I have incorrect syntax near "SELECT" and ")"

So my question is either how do I fix this query, or how can I use LINQ to populate my listview?


SELECT 
  Category.*, 
  (
    SELECT Top 1 Pictures.PictureFilePath 
    FROM Pictures 
    WHERE Category.CategoryID = Pictures.CategoryID 
  )
FROM
  Category
0

精彩评论

暂无评论...
验证码 换一张
取 消