douhan8581 2019-06-10 18:08
浏览 589


I have two select queries I want to combine for faster performance. I'm a bit confused as I'm not sure if I could use a JOIN or LEFT JOIN or something else to make it faster.

Here are the two queries I want to combine:

Query 1:

SELECT id FROM users WHERE email = :email LIMIT 1

Then, if that row exists from query 1, then run query 2:

SELECT * FROM settings WHERE id = :id_from_query_1

thank you for any kind of help!

  • 写回答

5条回答 默认 最新

  • dougehe2022 2019-06-10 18:17

    When making a join query you can specify what column to join on. In this case it would be:

    select, settings.*
    from users
    join settings on =

    You could also use a double from clause which I think results in the same speed background wise that would look like:

    select, settings.*
    from users, settings
    where =

    If proper indexes are set a join should be faster than 2 selects. Ofcourse there are many factors when it comes to speed like load, network, what is cached and what isn't etc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥60 Qcustomplot绘制实时动态曲线
  • ¥20 运用matlab画x-y图
  • ¥15 用idea运行项目,运行tomcat报错:断言失败
  • ¥15 Sqlserver查询链接服务器数据问题
  • ¥15 Bibtex4Word 引用中文文献
  • ¥20 用opencv c/c++ 转换成灰度图,然后做一下直方图均衡,输出mp4文件
  • ¥20 matlab中的双层数值积分
  • ¥50 服务器打印水晶报表问题
  • ¥30 gradle环境下javafx项目如何使用druid连接池
  • ¥15 服务器打印水晶报表问题