My goals is returning multiple types from a search query. I have two tables of users and movies. If search query is 'Mat', i should return both results for users with name like '%mat%' and movies with title '%mat%'.
I can use UNION or JOIN two tables in one request, but i guess there will be ordering problem.
For example i have this structure:
Users table:
id | name |
---|---|
1 | Mat |
My Answer:
2_Matt____3_Mateo____Movies table:_____id_title_____1_Matrix____2_Matilda____3_Batman____If i use UNION, the result will be like this:_1_Mat_2_Matt_3_Mateo_1_Matrix_2_Matilda_3_Batman_The ordering is mixed between users and movies. I want to separate the results for users and movies. Is there any way to achieve this?
Rate this post
4 of 5 based on 2236 votesComments