mysql如果搜索项已经在表中,则尝试从表中进行选择

时间:2013-12-18 13:10:20

标签: mysql

我正在尝试执行MySQL案例,该案例将根据输入执行不同的选择标准。更具体一点如果用户在html表单上选择一个选项,我希望案例在表格中搜索,看看是否存在与该选项匹配的条目。

"CASE 
            WHEN $destinationID NOT IN destinationexceptions.destinationid THEN
                SELECT file, destination, visa
                FROM output INNER JOIN file
                ON output.fileid=file.id
                INNER JOIN destination
                ON output.destinationid=destination.id
                INNER JOIN visatype
                ON output.visaid=visatype.id
                WHERE output.destinationid='$destinationID'
                AND output.visaid='$visaID'

            ELSE $destinationID IN destinationexceptions.destinationid THEN
                CASE
                    WHEN $nationalityID = destinationexceptions.nationalityid THEN
                        SELECT destinationid, nationalityid, file
                        FROM destinationexceptions
                        WHERE destinationid = '$destinationID'
                        AND nationalityid = '$nationalityID'
                        INNER JOIN file
                        ON destinationexceptions.fileid=file.id
                    ELSE
                        SELECT file, destination, visa
                        FROM output INNER JOIN file
                        ON output.fileid=file.id
                        INNER JOIN destination
                        ON output.destinationid=destination.id
                        INNER JOIN visatype
                        ON output.visaid=visatype.id
                        WHERE output.destinationid='$destinationID'
                        AND output.visaid='$visaID'
                END CASE
        END CASE";

到目前为止,我可以看到我的问题是查询不想在表中查看是否存在匹配项。不可避免的是,错误是1064访问或语法错误。

全部谢谢

0 个答案:

没有答案