V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
icemanpro
V2EX  ›  MySQL

支不支持 if exists()?

  •  
  •   icemanpro · 2021-02-07 10:12:45 +08:00 · 1590 次点击
    这是一个创建于 1171 天前的主题,其中的信息可能已经有所发展或是发生改变。
    像这样的,在 mysql 如何写?
    IF EXISTS(SELECT * FROM shares WHERE file_id='1' AND user_id='4') THEN
    SELECT * FROM shares WHERE file_id='1' AND user_id='4'
    ELSE
    SELECT * FROM shares WHERE file_id='2' AND user_id='5'
    END IF
    1 条回复    2021-02-07 11:50:08 +08:00
    ElmerZhang
        1
    ElmerZhang  
       2021-02-07 11:50:08 +08:00
    SELECT * FROM shares WHERE ( file_id='1' AND user_id='4' ) OR (file_id='2' AND user_id='5') ORDER BY file_id ASC LIMIT 1;
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   983 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 21:16 · PVG 05:16 · LAX 14:16 · JFK 17:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.