i have two tables like this
i want retrive cname from person where cid duplicated at per_db and did at per_db=$value
i want sql statment return "wael" from person

person
cname | cid
-----------
gamal | 1
wael | 2
samy | 3
-------------
per_db

cid | did
----------
1 | 1
2 | 1
2 | 2
3 | 2

any help

Recommended Answers

All 3 Replies

The english spell I with a capital "I". And they use punctuation marks.
It is not quite clear what you want: the person entries which appear more than once in per_db? Or the person entries where the number of occurences in per_db is the same as the value of the did field?
In the first case, this might help:

drop table if exists person;
create table person (cname varchar(255), cid integer);
insert into person values ('gamal',1), ('wael',2), ('samy', 3);
drop table if exists per_db;
create table per_db (cid integer, did integer);
insert into per_db values (1,1),(2,1),(2,2),(3,2);
select cname from person p, per_db pd where p.cid=pd.cid group by cname having count(cname) > 1

I get ($value) from another page and ($value)is array have more than one value
i want for each per_db.did=$value
and person.cid = per_db.did
return the Joint value
at person table is (wael)

So you have a fixed value you want to compare the per_db.did field to and join the two tables. Like that:

select cname from person, per_db where person.cid=per_db.cid and did=1;
select cname from person, per_db where person.cid=per_db.cid and did=2;
select cname from person, per_db where person.cid=per_db.cid and did=3;

with the last parameter walking throgh your $value array. [By the way, its a silly idea to call an array field "value". Of course it's containng values.]
But with your data, this query does not yield unique results:

select cname from person, per_db where person.cid=per_db.cid and did=1;
+-------+
| cname |
+-------+
| gamal |
| wael  |
+-------+
select cname from person, per_db where person.cid=per_db.cid and did=2;
+-------+
| cname |
+-------+
| wael  |
| samy  |
+-------+

There must be additional requirements to make it unique.

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.