Checking for duplicates in multiple tables (php, mysql)

The question was asked: 6 years 11 months ago   views: 38

Good time of day.

Guys, a question.

There are several tables, for example

table1 table2 table3 table4 ...

Each table has a certain field(all different) which contains the string, say the name.

The point is to run through all the tables, look in the box to each table and look for overlaps and if ONE is already the same field, making it a +1. Ie, say I add the name of the News - there is a check on these tables and if there is one news or News-2 News-3, then add +1 to the already existing.

An example of one table

$data = 'News'; $a = mysql_query("SELECT COUNT(news_title) AS count FROM news WHERE news_title LIKE '".$data."%'"); $r = mysql_fetch_assoc($a); $result = $r['count'] ? $data.'-'.($r['count']+1) : $data;

The question is how to do it on a bunch of tables with different fields in a convenient option?

Asked: 05-12-2012 в 10:42:02
Why many tables instead of one? Isn't it easier to use one table by adding new field, which will be able to classify data? - 05-12-2012 в 11:11:05
so originally it was done just wasn't necessary to check for uniqueness. remake makes no sense already. - 05-12-2012 в 11:17:26
But if these signs UNION with the necessary field to do (or in the view to render) and the result is to see - is not an option? - 05-12-2012 в 20:04:01

Answers   1


vskidku to make a table with metadata

table_name field_name Table1 field1 Table2 field2 Таблица3 field3

to pull data from it and dynamically generate the SQL query. You can still play with directories of MySQL and try from there to get information about tables and fields

Answered: 05-12-2012 в 11:12:32
I was thinking that it may do so If there is a match in the tables to collect these matches into an array and it has to do sorting and look for the value which is the largest account? - 05-12-2012 в 11:19:05