INTERSECT不工作

时间:2012-09-27 08:29:27

标签: php mysql

我正在php-mysql框架中执行一个mysql查询,该查询涉及2个查询结果的交集。但它没有执行。也许INTERSECT操作的语法需要改变。你能告诉我哪里出错了吗?

SELECT p.*
FROM property p
    , property_type pt
    , location l
    , city c
WHERE p.STATUS = 1
    AND p.prop_id = '1'
    AND p.property_type = 'Sale'
    AND (
        pt.prop_name LIKE '%dlf%'
        OR p.furnish LIKE '%dlf%'
        OR p.description LIKE '%dlf%'
        OR p.bed LIKE '%dlf%'
        OR p.term_condition LIKE '%dlf%'
        OR p.bedroom LIKE '%dlf%'
        OR p.property_type LIKE '%dlf%'
        OR c.city_name LIKE '%dlf%'
        OR (
            (
                p.location_id = l.loct_id
                AND l.loct_name LIKE '%dlf%'
                )
            )
        )
    AND p.prop_id = pt.prop_id
    AND p.city = c.city_id

INTERSECT

SELECT p.*
FROM property p
    , property_type pt
    , location l
    , city c
WHERE p.STATUS = 1
    AND p.prop_id = '1'
    AND p.property_type = 'Sale'
    AND (
        pt.prop_name LIKE '%sohna%'
        OR p.furnish LIKE '%sohna%'
        OR p.description LIKE '%sohna%'
        OR p.bed LIKE '%sohna%'
        OR p.term_condition LIKE '%sohna%'
        OR p.bedroom LIKE '%sohna%'
        OR p.property_type LIKE '%sohna%'
        OR c.city_name LIKE '%sohna%'
        OR (
            (
                p.location_id = l.loct_id
                AND l.loct_name LIKE '%sohna%'
                )
            )
        )
    AND p.prop_id = pt.prop_id
    AND p.city = c.city_id
ORDER BY sortnum LIMIT 0 , 30

但它显示错误:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'intersect Select p.* from property p,property_type pt,location l,city c where p.' at line 1

你能告诉我什么是正确的语法吗?

1 个答案:

答案 0 :(得分:2)

MySQL不支持INTERSECT,而是使用WHEREJOIN。请查看http://gablog.eu/online/node/33以获得解决方案。