F
F
flex22018-05-01 14:04:42
MySQL
flex2, 2018-05-01 14:04:42

How to make a request to select one record?

Hello everyone,
There are tables
categories
id,
name
--------------
items
id
category_id
name
So each category can have up to N number of item
I don’t understand how to put limit in join
The essence is this
I need select, for example, by where in (categories_ids) from the items table, one entry for each category, or to be more precise, for the last one.
Who faced? or who knows the solution?
Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Valitov, 2018-05-01
@flex2

If I understand correctly, then like this
sqlfiddle.com/#!9/180f22/46

E
Eugene, 2018-05-01
@klim76

instead of join use outer apply.
outer apply (select top 1 * from table t where t.category = outercategory ) qwerty

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question