SQL queries cleaner better in jquery

Total Post:154

Points:1086
 1168  View(s)
Ratings:
Rate this:

I have something like this:

SELECT cars.brand, cars.id FROM cars WHERE cars.brand = 4 LIMIT 1;
SELECT cars.brand, cars.id FROM cars WHERE cars.brand = 24 LIMIT 1;
SELECT cars.brand, cars.id FROM cars WHERE cars.brand = 29 LIMIT 1;

If will be more queries it will be very long. How do this in the other way, in one line? But important is for me speed. cars.brand = X AND LIMIT X is a variable so it maybe changes.

  1. Post:70

    Points:494
    Re: SQL queries cleaner better in jquery

    You are worried about having to send so many queries one by  one, so that would take a lot of time. You can make this one query instead:

    SELECT cars.brand, cars.id FROM cars WHERE cars.brand = 4 LIMIT 1
    UNION ALL
    SELECT cars.brand, cars.id FROM cars WHERE cars.brand = 24 LIMIT 1
    UNION ALL
    SELECT cars.brand, cars.id FROM cars WHERE cars.brand = 29 LIMIT 1;

      Modified On Apr-06-2018 04:54:06 AM

Answer