i must get data from four tables. i wrote the script with four queries, but i use it in ajax, and i wan’t to do it by one query.
here is queries…
$query1 = "SELECT `id`,`name_ar` FROM `tour_type` ORDER BY `order`";
$query2 = "SELECT `id`,`name_ar` FROM `hotel_type` ORDER BY `order`";
$query3 = "SELECT `id`,`name_ar` FROM `food_type` ORDER BY `order`";
$query4 = "SELECT `id`,`name_ar` FROM `cities` WHERE `id_parrent` = '$id_parrent' ORDER BY `name_ar`";
is it possible to write in one query?
thanks
structure of tables
tour_type
id | name_ar | name_ru | name_en | order |
food_type
id | name_ar | name_ru | name_en | order |
hotel_type
id | name_ar | name_ru | name_en | order |
cities
id | id_parrent | name_ar | name_ru | name_en | order |
The
UNION [ALL]function will allow you to combine more than one query, but the column data type and order must be identical between all queries. Additionally,UNIONwill remove duplicates – making it slower than usingUNION ALL(which will not remove duplicates).That said, UNION statements don’t allow for ORDER BY’s for each statement, but MySQL supports this if you place the query within brackets. Use: