doucuyu2259 2016-10-18 16:53
浏览 325
已采纳

SQL LIKE问题如果我想从我的user_id中选择1,它会选择1,10和11

I'm not really familiar with SQL and right now i have a problem with my query and it drives me insane i have 11 records with id and the id is just 1, 2, 3, .... and now if i have this query i want it to only output the record with id 1 but it also outputs records 10 and 11

This is my Query:

SELECT * FROM products WHERE id LIKE ?

and the bind parameter is:

$id

which in this case is 1 ($_GET['id'])

Thanks in Advance

  • 写回答

2条回答 默认 最新

  • douyi7283 2016-10-18 17:31
    关注

    Like does pattern matching and is used in conjunction with wildcard keys to find similar results. You are looking for an exact value, so just directly compare with an equal sign:

    SELECT * FROM products WHERE id =
    

    Using like, you could find anything containing a 1

    id like '%1%'
    

    or two digits where the first digit is a 1

    id like '1_'
    

    Here is the docs on TSQL's like operator. But think you just need =... https://msdn.microsoft.com/en-us/library/ms179859.aspx

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度