Second SELECT query if first SELECT returns 0 rows

前端 未结 5 1438
萌比男神i
萌比男神i 2020-12-01 16:31

I am trying to speed up a PHP script and I am currently pushing some PHP logic in the Mysql domain of the thing. Is there a way to make a different select query if the first

5条回答
  •  借酒劲吻你
    2020-12-01 17:12

    In a general case where you have multiple values for A (lets say, 'B', 'C', 'D', 'E', etc.) and you want to retrieve only the rows that belong to the lowest value that exists, then you would use the following query. This will work also for the particular case you exposed.

    SELECT p1.*
    FROM proxies p1
    LEFT JOIN proxies p2
        ON p1.A > p2.A
    WHERE p2.A IS NULL
    

    Fiddle

提交回复
热议问题