Created
August 2, 2019 01:45
-
-
Save camaleaun/96112453ddfc706c4e7ae7d196ce7f81 to your computer and use it in GitHub Desktop.
Comma group contact mysql select join
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE TABLE images ( | |
| meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT, | |
| post_id bigint(20) unsigned NOT NULL DEFAULT '0', | |
| image longtext, | |
| PRIMARY KEY (meta_id), | |
| KEY post_id (post_id) | |
| ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; | |
| INSERT INTO images (post_id, image) VALUES (2,'image1.jpg'),(2,'image2.jpg'); | |
| CREATE TABLE products ( | |
| ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, | |
| title text NOT NULL, | |
| PRIMARY KEY (ID) | |
| ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; | |
| INSERT INTO products VALUES (2,'Product'); | |
| -- SELECT p.title Name, GROUP_CONCAT(i.image) Images FROM products p JOIN images i ON p.ID = i.post_id GROUP BY p.ID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment