How to make a query for fetching a single record?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
20 views
Hi all,
There are tables

categories
id
name
--------------
items
id
category_id
name

So each category can be up to N number of item
I do not understand how to join to put a limit
Here's the essence
I need to choose for example where in (categories_ids) from the items table one record for each category, and to be more precise for the latter.
Who faced? or anyone knows a solution?
Thank you
by | 20 views

2 Answers

0 like 0 dislike
If I understand correctly, that's it
\rsqlfiddle.com/#!9/180f22/46
by
0 like 0 dislike
instead of join use outer apply.
outer apply (select top 1 * from table t where t.category = vneshnetorgovaja ) qwerty
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
asked Apr 11, 2019 by studprogrammist
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
110,608 questions
257,187 answers
0 comments
40,796 users