0

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

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by smantscheff
0

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
0

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)

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.