gpt4 book ai didi

php - 从 3 个表中选择 mysql 中的不同值

转载 作者:行者123 更新时间:2023-11-28 23:45:15 25 4
gpt4 key购买 nike

我有三个表,tbl_first_producttbl_third_producttbl_fourth_product

每个表有size1, size2, size3, size4, size5列。

例如,在tbl_first_product

id    size1    size2    size3    size4    size5

1 38 40 42 43 44
2 28 30 32 34 40

tbl_third_product

id    size1    size2    size3    size4    size5

1 30 32 40 0 0
2 28 30 32 34 0

tbl_fourth_product

id    size1    size2    size3    size4    size5

1 20 26 40 44 0
2 28 30 32 34 40

我想合并所有这些表并获得不同的值,输出应该是,

20 26 28 30 32 34 38 40 42 43 44

有什么方法可以使用 mysql 和 php 获取此输出。

我尝试了很多。但没有结果。

提前致谢。

最佳答案

您可以对每个字段执行 UNION 并从中SELECT DISTINCT

SELECT DISTINCT value
FROM
(SELECT size1 AS value FROM tbl_first_product

UNION

SELECT size2 AS value FROM tbl_first_product

UNION

SELECT size3 AS value FROM tbl_first_product

UNION

SELECT size4 AS value FROM tbl_first_product

UNION

SELECT size5 AS value FROM tbl_first_product

UNION

SELECT size1 AS value FROM tbl_third_product

UNION

SELECT size2 AS value FROM tbl_third_product

UNION

SELECT size3 AS value FROM tbl_third_product

UNION

SELECT size4 AS value FROM tbl_third_product

UNION

SELECT size5 AS value FROM tbl_third_product

UNION

SELECT size1 AS value FROM tbl_fourth_product

UNION

SELECT size2 AS value FROM tbl_fourth_product

UNION

SELECT size3 AS value FROM tbl_fourth_product

UNION

SELECT size4 AS value FROM tbl_fourth_product

UNION

SELECT size5 AS value FROM tbl_fourth_product) T
WHERE value <> 0

希望这对您有所帮助。

关于php - 从 3 个表中选择 mysql 中的不同值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33707698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com