i try to connect two tables with one query. My first is cards and there are single values. Each card has its card_id, and in other table 'decks', where in column cards i have collection of card_id (for example: 21,23,1,23) I want to get all cards in this collection with one query, and the query is:
SELECT *
FROM cards
INNER JOIN decks
ON cards.card_id IN decks.cards;
Can i do it like that? Or is there any other way to do this?
If decks.cards
is a comma separated list then use FIND_IN_SET()
:
SELECT *
FROM cards
INNER JOIN decks
ON FIND_IN_SET(cards.card_id, decks.cards);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.