【问题标题】:How to Make PHP/SQL Query to Select Rows Where Column Doesn't Equal Variable如何进行 PHP/SQL 查询以选择列不等于变量的行
【发布时间】:2014-05-07 16:22:52
【问题描述】:

我正在尝试使用 PHP 对 MSSQL 表进行查询,该表将查找具有不等于特定值的列的行。

我目前正在使用这个:

  $selecting6 = "select * from used_trailers1 where photo1='".$picature2."' or photo='".$picature2."' or name='".$picature2."' or photo2='".$picature2."' or photo3='".$picature2."' or photo4='".$picature2."' and Orderid isnot '".$id."'";

无济于事,此代码不起作用。

可以使用哪些正确的代码来选择不具有$id 值的行?

感谢您的帮助。感谢所有帮助。

【问题讨论】:

    标签: php sql sql-server row where


    【解决方案1】:

    试试这个

    $selecting6 = "select * from used_trailers1 where (photo1='".$picature2."' or photo='".$picature2."' or name='".$picature2."' or photo2='".$picature2."' or photo3='".$picature2."' or photo4='".$picature2."') and Orderid !='".$id."'";
    

    【讨论】:

    • 我接受你的回答,因为我先用了它,而且它有效。
    • @Kelsey 很高兴您的问题得到解决
    【解决方案2】:

    SQL 标准中的不等于运算符是<> 但 MySQL 和 SQL Server 也支持!=。阅读Comparison Operators in SQL ServerComparison Functions and Operators in MySQL

    SELECT [*] FROM [tbl] WHERE id <> $id
    

    【讨论】:

    • 我编辑了我的答案。但是&lt;&gt; 在 SQL 中是标准的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多