Oracle PHP display only once -
there 2 tables:
$inner_query = "select a.*, rownum rn, to_char(a.last_newsletter_modify, 'dd/mm/yyyy') last_newsletter_modify2 ".$db_schema_name."newsletter_subscription a, ".$db_schema_name."newsletter_type b, ".$db_schema_name."newsletter_subtyp_profile c a.id_subscription = c.id_subscription , c.id_type = b.id_type order e_mail";
if run query id_subscription 734 displays 3 times.
how can display once?
short answer: getting 1 row per newsletter_subtyp_profile
. subscription 734 linked 3 newsletter types, hence 3 rows of output.
you have 3 tables, not two, , question clearer if included full descriptions , sample data, , got rid of irrelevant php aspect , focussed on sql.
with detective work, make this:
create table newsletter_subscription ( id_subscription integer primary key , last_newsletter_modify date , e_mail varchar2(50) not null ); create table newsletter_type ( id_type integer primary key , description varchar2(40) not null unique ); create table newsletter_subtyp_profile ( id_subscription references newsletter_subscription , id_type references newsletter_type , constraint nsp_pk primary key (id_type,id_subscription) ); insert newsletter_subscription values (600, date '2017-01-10', 'someone@somewhere.net'); insert newsletter_subscription values (734, date '2017-02-05', 'someone@somewhereelse.net'); insert newsletter_subscription values (800, date '2017-03-01', 'nobody@nowherewhere.net'); insert newsletter_type values (1, 'type one'); insert newsletter_type values (2, 'type two'); insert newsletter_type values (3, 'type three'); insert newsletter_subtyp_profile values (734, 1); insert newsletter_subtyp_profile values (734, 2); insert newsletter_subtyp_profile values (734, 3);
now run query (i shortened select
list simplify output, , added b.description
- dummy column don't know other columns have on newsletter_type
):
select a.id_subscription, a.e_mail , to_char(a.last_newsletter_modify, 'dd/mm/yyyy') last_newsletter_modify2 , b.description newsletter_subscription a, newsletter_type b, newsletter_subtyp_profile c a.id_subscription = c.id_subscription , c.id_type = b.id_type order a.e_mail, c.id_type; id_subscription e_mail last_newsletter_modify2 description --------------- -------------------------- ----------------------- --------------------- 734 someone@somewhereelse.net 05/02/2017 type 1 734 someone@somewhereelse.net 05/02/2017 type 2 734 someone@somewhereelse.net 05/02/2017 type 3
btw logic clearer if used mnemonic aliases such sub
instead of a
newsletter_subscription
, , used standard ansi joins , lost uppercase:
select sub.id_subscription, sub.e_mail , to_char(sub.last_newsletter_modify, 'dd/mm/yyyy') last_newsletter_modify , typ.description newsletter_subscription sub join newsletter_subtyp_profile pro on pro.id_subscription = sub.id_subscription join newsletter_type typ on typ.id_type = pro.id_type sub.id_subscription = 734 order sub.e_mail, pro.id_type;
Comments
Post a Comment