Mysql search across multiple tables
I have three tables in my database which are: Show
Each of these tables has two fields called 'content' and 'title'. I want to be able to use 'Like' in my sql statement to look at 'messages.content', 'messages.title', 'topics.content', 'topics.title', 'comments.content' and 'comments.title' using a keyword. So far, my query is able to find results from only one table:
I am also wondering, once I get the results from multiple tables, how can I tell what result is from what table? Any help would be greatly appreciated!
OMG Ponies 318k78 gold badges511 silver badges494 bronze badges asked Jul 4, 2011 at 17:42
Eyad FallatahEyad Fallatah 1,8294 gold badges22 silver badges33 bronze badges 2
So, you are getting result from all of the three tables, and you can identify which row came from which table by looking at its answered Jul 4, 2011 at 17:48
MD Sayem AhmedMD Sayem Ahmed 28.2k26 gold badges109 silver badges177 bronze badges 4
What you are probably looking for is the UNION command:
answered Jul 4, 2011 at 17:50
Two search in other tables you use:
The CATEGORIES and POSTS are tables of your database. answered Jul 4, 2011 at 17:45
Bruno AlanoBruno Alano 6431 gold badge11 silver badges21 bronze badges 2 Html Search form:
Search.php:
include database.php in search.php
Donald Duck 7,84120 gold badges70 silver badges91 bronze badges answered Mar 5, 2017 at 15:03
How do I search for data in two tables in SQL?In SQL, to fetch data from multiple tables, the join operator is used. The join operator adds or removes rows in the virtual table that is used by SQL server to process data before the other steps of the query consume the data.
How retrieve data from 5 tables in SQL?Related. 3123. Add a column with a default value to an existing table in SQL Server.. 1132. SQL Update from One Table to Another Based on a ID Match.. 2297. Finding duplicate values in a SQL table.. 461. SQL query return data from multiple tables.. How do I search an entire database in MySQL?Find data across a MySQL connection by using the text search feature on any number of tables and schemas. From the schema tree, select the tables, schemas, or both to search and then right-click the highlighted items and click Search Data Table from the context menu.
How do you SELECT two tables in a single query?From multiple tables
To retrieve information from more than one table, you need to join those tables together. This can be done using JOIN methods, or you can use a second SELECT statement inside your main SELECT query—a subquery.
|