• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 162
  • Last Modified:

mysql select multiple tables

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
0
J N
Asked:
J N
  • 4
  • 3
  • 2
  • +1
5 Solutions
 
PortletPaulCommented:
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}
0
 
tel2Commented:
> 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.
0
 
Ray PaseurCommented:
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
J NUnicorn wranglerAuthor 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%'
0
 
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%'
0
 
tel2Commented:
...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
        table1.id = table2.table1_id AND
        table1.id = table3.table1_id AND
        (column1 LIKE 'something%' OR
        column2 LIKE 'something%' OR
        column3 LIKE 'something%' OR
        field2  LIKE 'something%')
0
 
Ray PaseurCommented:
@tel2: Good point.  A GROUP BY clause may be helpful, too.
0
 
J NUnicorn wranglerAuthor 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

0
 
tel2Commented:
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.
0
 
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.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_7830-A-Quick-Tour-of-Test-Driven-Development.html
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now