I execute this two queries one by one but i need to execute this two queries as one query same time and get result from mysql database once
I tried UNION SELECT but because of select different coulmns (model,modelsnumber) from different tables it's not working
Does anybody knows sql query structure to help me to solve this problem?
query 1
$query = "SELECT post_id,SUBSTR(post_name, 1 ,30) as post_name,price,username,poster_folder_id FROM realestate
USE INDEX(idx_post_id,idx_name,idx_price,idx_username,idx_poster_folder_id)
WHERE post_name LIKE ? OR description LIKE ? OR price LIKE ? ORDER BY post_id DESC LIMIT 10";
query 2
$query = "SELECT post_id,SUBSTR(post_name, 1 ,30) as post_name,price,username,poster_folder_id FROM cars
USE INDEX(idx_post_id,idx_name,idx_price,idx_username,idx_poster_folder_id)
WHERE post_name LIKE ? OR description LIKE ? OR model LIKE ? OR modelsnumber LIKE ? OR price LIKE ? ORDER BY post_id DESC LIMIT 10";
I tried
$query = "SELECT post_id,SUBSTR(post_name, 1 ,30) as post_name,price,username,poster_folder_id FROM realestate
WHERE post_name LIKE ? OR description LIKE ? OR price LIKE ? ORDER BY post_id DESC LIMIT 10
UNION
SELECT post_id,SUBSTR(post_name, 1 ,30) as post_name,price,username,poster_folder_id FROM cars
WHERE post_name LIKE ? OR description LIKE ? OR model LIKE ? OR modelsnumber LIKE ? OR price LIKE ? ORDER BY post_id DESC LIMIT 10";