database - How to get values from a table where value depends on another table? -


hi i'm using oracle database using oracle 10g. have 2 tables car , owns.

create table car( "license" varchar(255) not null primary key, "year" varchar(255), "model" varchar(255) ); 

i inserted these values

insert car values('12-3000', '2012', 'axio'); insert car values('11-3000', '2008', 'corolla'); insert car values('12-4000', '2013', 'axio'); insert car values('12-5000', '2013', 'premio'); insert car values('11-5000', '2010', 'nano'); insert car values('11-6000', '2011', 'alto'); insert car values('12-6000', '2015', 'nano twist'); 

this owns table

create table owns ( "nid" varchar(20) not null, "license" varchar(255), primary key("nid", "license") ); 

also inserted values

insert owns values('123451', '11-3000'); insert owns values('123452', '12-4000'); insert owns values('123453', '12-5000'); insert owns values('123454', '11-5000'); insert owns values('123455', '11-6000'); insert owns values('123456', '12-6000'); insert owns values('123457', '12-3000'); 

now need find national id (nid) of person has "axio" models. how write query? may kind...

select "nid" owns "license" = (select "license" car "model" = 'axio'); 

thanks in advance.

try this,

select "nid" owns "license" in (select "license" car "model" = 'axio');

you can try using joins well...


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -