You Asked
Hi
I am trying to get columns from a table only if that column value is set as "YES" in another lookup table.
Please help me to get the query for the same.
I have a lookup table like this:
create table cust_bug_lookup(Title varchar2(100), Last_update DATE, created_by varchar2(100),START_DATE DATE, END_DATE DATE,product_id varchar2(100),BUG_NUMBER varchar2(100),component varchar2(100),analyzed_by varchar2(100),root_cause varchar2(100));
insert into cust_bug_lookup(Title,product_id,BUG_NUMBER, component, analyzed_by, root_cause ) values('test123',5,'yes','no','yes','no');
I have another table:
create table cust_bug_value(product_id number, bug_number number, component varchar2(50), analyzed_by varchar2(50), root_cause varchar2(50));
insert into cust_bug_value(product_id, bug_number, component, analyzed_by, root_cause) values(5,1234564,'extract','subhash','this is test issue')
Now I want to select only columns from cust_bug_value where column value is set as "yes" in cust_bug_lookup
so my select query should return output like:
product_id bug_number analyzed_by
---------- ----------- ----------
5 1234564 subhash
my select query should be like as follows:
select ---------------- from cust_bug_value where product_id=5;
could you please let me know the select query for above output using above 2 tables?
Thanks,
Subhash
and Connor said...
I think you're heading down a bad road here.
There is a line to be drawn between
- what the database holds (ie, data)
- what is presented to the user/customer (ie, the window on that data)
So there is nothing wrong with holding the *information* about the output in the database (ie, your cust_bug_lookup table), but when it comes to querying the data, I think you'll be much better off with your query to the database getting (in general) all the columns from cust_bug_value, and your application tool (eg a reporting tool, or application express, etc) being in charge of using the information in cust_bug_lookup to then render that information to the screen.
Otherwise you are definitely into dynamic SQL territory, which will just be unpleasant all around, because *every* query will need to be dynamically generated.
Rating
(1 rating)
Is this answer out of date? If it is, please let us know via a Comment