如何用三个不同的列搜索三个不同的表?当前命令:

$sql="select t1.brand_name,t2.category_name from brand_data_add AS t1
      LEFT JOIN category_add_data AS t2 ON t1.brand_name=t2.category_name
      UNION select t1.brand_name,t2.category_name from brand_data_add AS t1
      RIGHT JOIN category_add_data AS t2 ON t1.brand_name=t2.category_name";

最佳答案

SQL:

SELECT
    *
FROM
    (
    SELECT
        workouts.name,
        workouts.description,
        `user`.user_email
    FROM
        workouts
    LEFT JOIN `user` ON
        workouts.created_by = `user`.iduser
UNION
    SELECT
        workouts.name,
        workouts.description,
        `user`.user_email
    FROM
        workouts
    RIGHT JOIN `user` ON
        workouts.created_by = `user`.iduser) AS main_table
WHERE
    user_email LIKE '%gmail%';


说明:


您应将并集查询用括号括起来
使用SELECT子句获取字段
使用WHERE子句在虚拟表main_table中进行条件过滤(两个表的结合)

10-06 07:04