【问题标题】:mySQL How to select distinct(1 column : pruduct_Type) from 1st table and select 2 columns from 2nd tablemySQL如何从第一个表中选择不同的(1列:pruduct_Type)并从第二个表中选择2列
【发布时间】:2020-02-08 20:41:13
【问题描述】:

我有 2 个表,我会从第 2 个表中选择 2 列,用于从第 1 个表中明显选择的不同产品类型。

表 1:
idTable1 product_Type product_name
1            AD                  产品 N1
2            AD                  产品 N2
3             AF                  产品 N3
4             AF                  产品 N4

表 2:
idTable2 typeISO 厂商电话
21           AD         阿迪达斯          121212121
22           AF         Lacoste          989898989
23           AX         耐克              333333333

我会回来的:

数组:
product_Type 厂家电话
AD                 阿迪达斯           121212121
AF                  Lacoste          989898989

我测试了这个查询,但只返回一列:product_Type:

SELECT DISTINCT 1stTable.product_Type 从第一个表 左加入第二个表 ON 1stTable.product_Type = 2ndTable.typeISO

谢谢

【问题讨论】:

    标签: mysql phpmyadmin


    【解决方案1】:

    我想你在找exists:

    select t2.*
    from table2 t2
    where exists (select 1 from table1 t1 where t1.product_type = t2.typeISO)
    

    这将为您提供table2 中的所有记录,其typeISO 可在table1product_type 列中找到。

    【讨论】:

    • 没关系,谢谢,你救了我很多。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-14
    • 1970-01-01
    • 2015-12-13
    • 2017-12-16
    • 2012-04-01
    • 2012-11-03
    相关资源
    最近更新 更多