多个查询需要组合结果phpMyAdmin

时间:2011-07-25 16:43:56

标签: mysql sql select phpmyadmin

在phpMyAdmin的SQL窗口中显示了一个分隔符;查询之间。它运行我在其中的所有查询只显示最后一个的结果。如何将结果合并到一个?

SELECT  field1, field2, field3, field4, field5, field6 
FROM table WHERE field2 = "AA" AND field3 LIKE '%BBB%';
SELECT  field1, field2, field3, field4, field5, field6 
FROM table WHERE field2 = "AA" AND field3 LIKE '%CCC%';

1 个答案:

答案 0 :(得分:1)

UNION怎么样?

SELECT  field1, field2, field3, field4, field5, field6 
FROM table WHERE field2 = "AA" AND field3 LIKE '%BBB%'
UNION
SELECT  field1, field2, field3, field4, field5, field6 
FROM table WHERE field2 = "AA" AND field3 LIKE '%CCC%';

<强>更新

简化查询:

SELECT  field1, field2, field3, field4, field5, field6 
FROM table WHERE field2 = "AA" AND (field3 LIKE '%BBB%' OR field3 LIKE '%CCC%')