I have 3 tables with data. Let's call them
cars
trucks
boats
If the data from either one was refered from table blah then index_table has a record of it.
Ex.
We used refered to a row from table cars in table blah, so now we have an entry 33 in index_table. Table blah contains a note of this entry in it's column and has a value 33, i.e. identical to the ID of the record in index_table, and so on.
I need to run a search query for a particular name in all three (cars, trucks and boats) tables and return the value ONLY if it has been already used and has a record of it in the index_table.
I put separate lines of code that I hope could accomplish this task. The problem is that I am not sure how to put all these separate pieces together. Here's what I've got:
SELECT id, name FROM cars WHERE name like '%".$_POST['q']."%'
SELECT id, name FROM trucks WHERE name like '%".$_POST['q']."%'
WHERE EXISTS (SELECT refID FROM index_table WHERE index_table.refID = cars.id)
WHERE EXISTS (SELECT refID FROM index_table WHERE index_table.refID = trucks.id)
Now I do not particularly insist on having to use these particular elements. If there's a better way of doing it, I'd be hapy to give it a whirl.