Hey guys complete noob/novice here,

Looking to join multiple tables identical in structure. It's meant for a search box in my school project.

If I have table 1 and table 2 identical in structure, when the user searches for "keyword" it will search through both table 1 and table 2 and return the results from both. As it stands I only have it returning results from table 1.

I did google this first, found this thread.
http://www.daniweb.com/web-development/databases/mysql/threads/378594
Seems like brillig might have the right solution, but honestly, I'm trying to follow how he came up with that, I've tried multiple ways and I'm getting errors/no results.

Here is a snippet of my code if it helps. Articles2 is my table, I'd like to search both articles2 and articles3.

$results = "SELECT `title`, LEFT(`description`, 70) as `description`, `url` FROM `articles2` WHERE $where";
$results_num = ($results = mysql_query($results)) ? mysql_num_rows($results) : 0;

Also, if I could make one big table that would be great, but it seems the current table won't go past 4,993 records, if there was a way to increase this I wouldn't bother with this.

If you need more info please let me know, I think I need UNION but I'm not exactly sure how to write it, the examples and answers I've seen across the web haven't been new user friendly, so any help would be appreciated.

combine the two tables first.

SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name

Member Avatar for diafol

To combine two identically structured tables use UNION, no need for a join.

e.g.

$result = mysql_query("(SELECT field1,field2,field3 FROM table1 WHERE field1='$value1')UNION(SELECT field1,field2,field3 FROM table2 WHERE field1='$value1')");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.