mysql select multiple tables


I want to make a search function on a website and i would like to create a sql query that searches all of my preferred tables in my sql database and see if anything matches. i was thinking that i would have to use wildcards but im not sure how i could accomplish this or even if its possible

the list of my tables are
Home Log out Query window  phpMyAdmin documentation  Documentation
- bushbase (21)

thanks in advance
J NUnicorn wranglerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This is way too broad to answer in my view.

a typical SQL query requires field names

SELECT field1, field2 FROM anytable WHERE field1 LIKE 'something%' OR field2 LIKE 'something%'

Perhaps you have implemented some full text indexes?

SELECT * FROM anytable  WHERE MATCH (title,body) AGAINST ('something')

{edit: it is MySQL}
> This is way too broad to answer in my view.
Agreed.  Perhaps the asker is wanting a way-too-broad answer.  Allow me:

    Yes, it is possible.

Comforting, ain't it?
Sorry, I wasn't able to go into detail with column names, etc, because I don't know them.
Glad to be of service.
Please don't give me all the points.  Portlet deserves some, too.
Ray PaseurCommented:
When it comes to "search" Google kind of owns the space.  They can build a custom search engine for your site.

I have used Atomz, Freefind, and Wrensoft "Zoom" search with good results, too.  My point here is that you do not need to go back in time a dozen years to reinvent the future of web search as it was back then, before modern technology took over.  Just use the inventions of others!  Many are free and open source and all of them have at least a dozen years (and hundreds of millions of dollars) head-start on anything you can begin building today.
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

J NUnicorn wranglerAuthor Commented:

Thanks for your responses

1) i have used zoom before but i always have to update it and adjust some of the settings which i do not like.
2) i have looked into google but i was unable to  update the styling  so i did not like it

i just want to know how i would select multiple tables:

SELECT * FROM table1, table2... WHERE column1, column2, column3 LIKE 'something%' OR field2 LIKE 'something%'
Ray PaseurCommented:
I think you're pretty close with the SELECT you posted.  Have you tried that yet?  Maybe this variant would be more on point.  You may have to disambiguate the table+column combinations if there are columns in two tables with the same names.

SELECT column1, column2
FROM table1, table2
WHERE column1 LIKE 'something%'
OR    column2 LIKE 'something%'
OR    column3 LIKE 'something%'
OR    field2  LIKE 'something%'
...and you may get more output row combinations than you want, unless you add a condition that links the tables by foreign keys (if applicable), e.g.
    SELECT column1, column2
    FROM table1, table2, table3
    WHERE = table2.table1_id AND = table3.table1_id AND
        (column1 LIKE 'something%' OR
        column2 LIKE 'something%' OR
        column3 LIKE 'something%' OR
        field2  LIKE 'something%')
Ray PaseurCommented:
@tel2: Good point.  A GROUP BY clause may be helpful, too.
J NUnicorn wranglerAuthor Commented:

So i made the following SQL
SELECT * FROM blog, bucket_list, destinations, drinks, events, games, help, music, news, pages, photos
	    WHERE  status='active' AND (
		title LIKE (:title) OR image LIKE (:image) OR photographer LIKE (:photo) OR date LIKE (:date) OR
		author LIKE (:author) OR content LIKE (:content) OR tags LIKE (:tags) OR tagline LIKE (:tagline) OR 
		category LIKE (:cat) OR location LIKE (:loc) OR city LIKE (:city) OR country LIKE (:country) OR latitude LIKE (:lat) OR
		longitude LIKE (:long) OR start_date LIKE (:start) OR fin_date LIKE (:end) OR ingredients LIKE (:item) OR
		difficulty LIKE (:bitch) OR occasion LIKE (:occ) OR type LIKE (:type) required_items LIKE (:required) OR
		url_link LIKE (:url) OR name LIKE (:name) OR genre LIKE (:genre) OR artist LIKE (:artist) OR personal_desc LIKE 
		(:desc) OR source_uploader LIKE (:uploader) OR source_description LIKE (:src_desc) OR
		header1 LIKE (:header1) OR header2 LIKE (:header2) OR header3 LIKE (:header3) OR header4 LIKE (:header4) OR
		header5 LIKE (:header5) OR content_title1 LIKE (:title1) OR content_title2 LIKE (:title2) OR link LIKE (:link) OR
		trip LIKE (:trip) )

Open in new window

and im not yielding any results

    [:title] => %$search_item%
    [:image] => %$search_item%
    [:photo] => %$search_item%
    [:date] => %$search_item%
    [:author] => %$search_item%
    [:content] => %$search_item%
    [:tags] => %$search_item%
    [:tagline] => %$search_item%
    [:cat] => %$search_item%
    [:loc] => %$search_item%
    [:city] => %$search_item%
    [:country] => %$search_item%
    [:lat] => %$search_item%
    [:long] => %$search_item%
    [:start] => %$search_item%
    [:end] => %$search_item%
    [:item] => %$search_item%
    [:bitch] => %$search_item%
    [:occ] => %$search_item%
    [:type] => %$search_item%
    [:required] => %$search_item%
    [:url] => %$search_item%
    [:name] => %$search_item%
    [:genre] => %$search_item%
    [:artist] => %$search_item%
    [:desc] => %$search_item%
    [:uploader] => %$search_item%
    [:src_desc] => %$search_item%
    [:header1] => %$search_item%
    [:header2] => %$search_item%
    [:header3] => %$search_item%
    [:header4] => %$search_item%
    [:header5] => %$search_item%
    [:title1] => %$search_item%
    [:title2] => %$search_item%
    [:link] => %$search_item%
    [:trip] => %$search_item%

Open in new window

Hi M. Jayme Nagy,

I'm not familar with your "(:title)" syntax, as I'm not a PHP expert, but I suggest you start with something very simple, and get that working, and then make it more complex until you get what you want.  Start with something short, that you know should work (i.e. there is data in the table that matches the conditions).

SELECT * FROM blog, bucket_list, destinations, drinks, events, games, help, music, news, pages, photos
          WHERE status = 'active' AND (
            title LIKE "%something-that-is-in-this-field%" )

When you get that working, try using your variable, like this:

SELECT * FROM blog, bucket_list, destinations, drinks, events, games, help, music, news, pages, photos
          WHERE status = 'active' AND (
            title LIKE (:title) )

If that works, expand it further.

And I suggest you use this "don't try to run until you can crawl" method for the rest of your life.  Well, you can try to run first, but if you fall over (i.e. the code falls over), then go back to crawling for a while, again.
Ray PaseurCommented:
Completely agree with @tel2.  Start with a simple (as in "Drop-dead Simple") example that uses one table and one column. Then begin adding to the problem definition.  You may find that test-driven development is a useful concept.  The article here is not about crafting MySQL queries, but it shows the thought processes and design patterns that professionals follow when confronted by unique and unknown problems.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.