Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 如何使用一个id将四个表连接在一起_Html_Sql - Fatal编程技术网

Html 如何使用一个id将四个表连接在一起

Html 如何使用一个id将四个表连接在一起,html,sql,Html,Sql,我有四个表,我想使用SQL查询连接它们,并在产品页面上显示产品 Table 1 [table name: A] has product_id and category_id, Table 2 [table name: B] has product_id, and our_price, Table 3 [table name: C] has product_id, and product_name Table 4 [table name: D] has product_id, descr

我有四个表,我想使用SQL查询连接它们,并在产品页面上显示产品

Table 1 [table name: A] has product_id and category_id, 
Table 2 [table name: B] has product_id, and our_price,  
Table 3 [table name: C] has product_id, and product_name  
Table 4 [table name: D] has product_id, description, and saving_price.
这里,我想

加入表A、B、C和D
从表B、C、D中选择表A中类别id=77的所有产品
数据


我想在类别id为77的产品页面上打印
产品名称、说明、保存价格和我们的价格

这大概就是你想要的,尽管从你的提问方式很难知道

SELECT
    A.product_id,
    A.category_id,
    B.our_price,
    C.product_name,
    D.description,
    D.saving_price
FROM
    A
    INNER JOIN B ON A.product_id = B.product_id
    INNER JOIN C ON A.product_id = C.product_id
    INNER JOIN D ON A.product_id = D.product_id
WHERE
    A.category_id = 77

以上假设所有表中都存在数据。如果您在某些情况下缺少数据,您可能需要使用
左侧外部联接

,请参阅您的请求,并说明具体的操作方法。。。你尝试过什么?你应该阅读OP中的评论并分析OP的努力,你不应该向他提供答案,说真的,他是个初学者,如果他从未尝试过一次,这对他没有好处,不要介意只是说