开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜