PDA

View Full Version : Searching multiple mysql tables, JOINS?


NerdArmy
12-03-2011, 03:04 AM
I'm creating a mysql keyword search on my website and I know how to search a single mysql table, my problem is I need to search 15 different tables simultaneously, they also all have the same column names. I was told I have to you JOINS but i've never used them before. How is this done?



MY SQL SELECT:


SELECT *
FROM mytable1

WHERE keyword LIKE %colname% OR id LIKE %colname%

edbr
12-03-2011, 03:24 AM
"SELECT * FROM table1 JOIN table2 ON table1.title=table2.title where......"

this will join table1 to table2 where title on 1 and 2 are equal

davidj
12-09-2011, 03:54 PM
I would create a VIEW in MYSQL with your joins defined. It will be a lot quicker.

A view behaves like a virtual table which already has the joins indexed so you just need to run a simple SELECT on the view