我有表 '文章'如何從兩個表格中進行選擇?
+-------------+ | articles | +----+--------+ | id | title | +----+--------+ | 1 | title1 | +----+--------+ | 2 | title2 | +----+--------+ | 3 | title3 | +----+--------+
表 '目錄'
+---------------------+ | catalogue | +----+--------+-------+ | id | group | name | +----+--------+-------+ | 1 | group1 | name1 | +----+--------+-------+ | 2 | group1 | name2 | +----+--------+-------+ | 3 | group2 | name3 | +----+--------+-------+ | 4 | group2 | name4 | +----+--------+-------+
綁定表 'bindTable'
+------------+--------------+-------+ | bindTable | +------------+--------------+-------+ | id_article | id_catalogue | value | +------------+--------------+-------+ | 1 | 2 | 1 | +------------+--------------+-------+ | 1 | 3 | 4 | +------------+--------------+-------+ | 3 | 1 | 2 | +------------+--------------+-------+ | 3 | 3 | 1 | +------------+--------------+-------+ | 3 | 4 | 3 | +------------+--------------+-------+
和我需要得到結果如表 '結果' ,在那裏我可以得到配對「catalogue_name:價值」從表'文章'的選定項目
+-----------------------------------------------------+ | result | +------------+---------------+----------------+-------+ | article_id | article_title | catalogue_name | value | +------------+---------------+----------------+-------+ | 1 | title1 | group1_name2, | 1 | | | | group2_name3 | 4 | +------------+---------------+----------------+-------+ | 3 | title3 | group1_name1, | 2 | | | | group2_name3, | 1 | | | | group2_name4 | 3 | +------------+---------------+----------------+-------+
任何人都可以告訴我一個查詢字符串與一個數據庫查詢?感謝您的關注。
My vision: SELECT b.id_article, a.title, c.group, c.name, b.value FROM bindTable b JOIN articles a ON a.id = b.id_articles JOIN catalogue c ON c.id = b.id_catalogue WHERE b.id_article = 1
,但我需要一個一行對c.name & b.value一個a.id
值'''也像'catalogue_name'一樣是'concat'? –
沒關係,只有名字 – Alaksander
你試過什麼查詢?你學會了如何做JOIN?當慾望輸出不清晰時, – user3741598