S
S
sarvatas2018-06-08 11:05:31
MySQL
sarvatas, 2018-06-08 11:05:31

How to overcome duplicate output in mysql (5.7) with join and json?

Good afternoon. Need help. I am querying two database tables in one query.
The second table (first_table) has a "ids" field in json format, where an array of the form ["1", "2", "3"] is stored.
The first table (second_table) has an id field. You need to make a selection where the id from the first table is contained in the ids of the second table, in addition to another selection for other parameters.
I make a query:
SELECT `first_table`.`id` AS `id`,
...
FROM
`first_table`
LEFT JOIN
`second_table`
ON JSON_SEARCH(first_table.ids, 'one', second_table.id) IS NOT NULL ...
The selection works fine, but the problem is that there is a duplication of the output for the number of values ​​in the json array. Those. if there are 5 elements in the ids array, and only one id, then the output is duplicated 5 times. Distinct and group gives no results. I don't know how to remove the duplication. Thanks for the help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question