SQL QUERIES CLEANER BETTER IN JQUERY

Manoj Bhatt

Total Post:154

Points:1086
Posted by  Manoj Bhatt
 892  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 change.

  1. Simons Hood

    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;

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!