L
L
lolrofl012019-01-23 22:34:50
Search engines
lolrofl01, 2019-01-23 22:34:50

How to organize a search in 3 tables at once?

Good afternoon!
There are 3 tables: cars, planes, trains.
Each of them has a varchar field name.
There is a search string, the user enters the name into it, after the 3rd letter entered, the search should begin in all 3 tables, and the first 10 results with the best occurrence should be displayed. How can this be built using php + sql?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Anton, 2019-01-24
@lolrofl01

As an option, you can make a common transport table containing the name field for all modes of transport. And to connect your tables to the general through join as necessary.
In this case, the search will be much faster and easier. And only one table.

S
sorokinfil, 2019-01-23
@sorokinfil

If pagination is not needed, then UNION queries should help. Otherwise, you will have to make a separate table purely for FULLTEXT with foreign keys.

K
Konstantin Tsvetkov, 2019-01-23
@tsklab

There is no "best match" in the SQL standard. It is necessary to use text search of a specific DBMS.
Build a view to join tables.

S
Sergey S., 2019-01-24
@seganim

If they have the same structure, then UNION all 3 tables, bringing them to the view, text search. More or less like this:
If there is Textsearch in the table type, you can also search for it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question