C
C
coderisimo2015-10-26 22:27:47
MySQL
coderisimo, 2015-10-26 22:27:47

Is it possible to query SQL (MySQL) to get all data at once?

Is there a way to get data in one request?
315c95dde7ac41298c7a28210b50255d.jpg
https://dl.dropboxusercontent.com/u/19954007/asks/...
I need that when searching for the substring "SHA" I get:
'title' 'tags' KOLYA
SHA,HA
SASHA OP
of the tags was the searched substring, the second, since the searched substring was found in its header.
i.e., so that the search is performed in pages (by partial match with the title) and by tags (also by partial match) . And, if either the title or one of the tags matched, the entry was returned with the title and ALL of its tags.
I started with GROUP_CONCAT, but I was blown away)))))), of course, it was possible to organize the base differently, but alas .... this is a given )
Thank you

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2015-10-26
@coderisimo

SELECT `p`.`title`, GROUP_CONCAT(`t`.`tag` SEPARATOR ',')
    FROM `page_tag` AS `pt`
    JOIN `tag` AS `t` ON `t`.`id` = `pt`.`tag_id`
    JOIN `pages` AS `p` ON `p`.`id` = `pt`.`page_id`
    GROUP BY `p`.`id`

D
Dmitry Kovalsky, 2015-10-26
@dmitryKovalskiy

More or less like this.

SELECT *(убрать звездочку, перечислить нужные столбцы) FROM Pages as p
LEFT JOIN page_tag as pt ON pt.pageId = p.Id
INNER JOIN tag as t ON t.tag_id = pt.tag_Id
WHERE <Условия фильтрации>

Deal with JOIN

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question