FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


mysql - doubles





sonam
I have seven tables with same fields: name, surname, title, etc. I would like to check are some doubles in this seven tables, and I must check trought title. Are there some mysql solution for this check because I can do this easy with php.

Sonam
AftershockVibe
By doubles do you mean duplicates? (double is also a numeric data type).

You can do something along the lines of
Code:
select field_name, count(*) as dupes
 from table_name
group by dupes
having  dupes > 1


How you fix them is then up to you. Cool
kv
A small correction

Code:


select field_name, count(*) as dupes
from table_name
group by field_name
having  dupes > 1



In your case

Code:


select title, count(*) as dupes
from table_name
group by title
having  dupes > 1

AftershockVibe
Oh yeah... sorry Sonam.
Cheers for the fix kv.
sonam
Ah, sorry, now when I read my post I see how is bad my English. Thanks, AftershockVibe and kv, but if I good understand yours sql will take out doubles from one table. Am I right? I would like to compare two (or more) tables. For example:

Table One:
name......title..........rest
John.......BCC.......something
Mery.......Dir ........something
Luis ...... Scc ....... something

Table Two:
name.......title...........rest
Sonam.....ACC......something
Harry ......FCC...... something
Stella ......BCC ......something

Now I would like to find out John and Stella because they have the same title (BCC).

Sonam
kv
Code:


select title, count(*) as dupes
from table_name_1

UNION ALL

select title, count(*) as dupes
from table_name_2

UNION ALL

select title, count(*) as dupes
from table_name_3

/* ... and so on for all the tables */

group by title
having  dupes > 1

sonam
Thanks kv but I need little bit more help. How I can create php mysql_query and echo $result? I was try something, but I didn't get result.

Sonam
rvec
http://nl.php.net/manual/en/function.mysql-fetch-array.php
Quote:
Code:
<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or
    die("Could not connect: " . mysql_error());
mysql_select_db("mydb");

$result = mysql_query("SELECT id, name FROM mytable");

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    printf("ID: %s  Name: %s", $row["id"], $row["name"]);
}

mysql_free_result($result);
?>

something like that. But instead of mysql_fetch_array there are some other ways to get the values. For example mysql_ fetch_ field or mysql_ fetch_ object. To see which one you need take a look at the documentation on http://nl.php.net/manual/en/ref.mysql.php
sonam
Thanks rvec but I am asking for query independent to my first post. I know query for one table, but I have problem to find out doubles in few tables at once (not one by one). kv is give me good point, but when I try to create query from his post, I didn't get result.

Sonam
Related topics
mysql connection question
php admin and mysql admin console
Mysql And PHP HELP PLZ
Do you use a CMS script?
Question about MySQL!
PHP, MySQL...
PHP Book (Php and Mysql for Dynamic Web Sites)
few mysql questions
E-Cards with PHP & MySQL
HTTP AUTH with PHP and mySQL
Build an online dictionary by PHP/MySQL
Make search engine With PHP and mySQL, for your site
PHP without mySQL
Multiple versions of PHP/MySQL
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.