We help IT Professionals succeed at work.

mysql select multiple tables

J N
J N asked
on
181 Views
Last Modified: 2014-08-12
Hi,

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)
bb_users
blog
bucket_list
destinations
drinks
events
games
help
music
news
pages
photos


thanks in advance
Comment
Watch Question

PortletPaulEE Topic Advisor
CERTIFIED EXPERT
Most Valuable Expert 2014
Awarded 2013

Commented:
This is way too broad to answer in my view.

a typical SQL query requires field names

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

but:
Perhaps you have implemented some full text indexes?

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

{edit: it is MySQL}
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Most Valuable Expert 2011
Author of the Year 2014

Commented:
When it comes to "search" Google kind of owns the space.  They can build a custom search engine for your site.
https://support.google.com/customsearch/answer/72325?hl=en

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.
J NUnicorn wrangler

Author

Commented:
Hi,

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%'
Most Valuable Expert 2011
Author of the Year 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Most Valuable Expert 2011
Author of the Year 2014

Commented:
@tel2: Good point.  A GROUP BY clause may be helpful, too.
J NUnicorn wrangler

Author

Commented:
Hi,

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

Array
(
    [: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

CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Most Valuable Expert 2011
Author of the Year 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.