• Aditya-313343 - Tuesday, August 15, 2017 6:36 PM

    >> I need a help in writing a query. <<

    No you need help understanding how RDBMS works. You still basically writing assembly language programming. First of all, we need DDL. This is been netiquette on SQL for forums for over 30 years; why does this doesn't apply to you?

    Unlike filesystems, which can use a physical record address, an identifier in RDBMS must be for a particular kind of entity. There is no such crap as a generic "id" in RDBMS. By definition, every table must have a key, but since you just posted a silly ASCII picture , we have to guess what the tables look like.

    CREATE TABLE Foobar
    (foo_id CHAR(1) NOT NULL,
    tab_name CHAR(2) NOT NULL,
    PRIMARY KEY (foo_id, tab_name),
    stupid_flg SMALLINT NOT NULL
     CHECK(stupid_flg IN (0 ,1));

    You have no idea how RDBMS is supposed to work. Approval is not an attribute! It is the value of some attribute, such as "credit checking", "job application", etc. you're still writing with assembly language flags and don't know how to do a valid data model.

    Also identifiers cannot be numerics because you don't do any math on them. Yes, I know in programming languages like COBOL or assembly language, there's no strong distinction between strings and numerics.

    Your query is an attempt in DML to correct the DDL you messed up.

    CREATE TABLE Foobar
    (foo_id CHAR(1) NOT NULL PARIMARY KEY,
    ab_status CHAR(1) NOT NULL
     CHECK (ab_status in ('Y', 'N'),
    cd_status CHAR(1) NOT NULL
     CHECK (cd_status in ('Y', 'N'),
    ef_status CHAR(1) NOT NULL
     CHECK (ef_status in ('Y', 'N'));

    You need to get a book on basic data modeling, basic RDBMS and read the forum rules about postings.

    Please post DDL and follow ANSI/ISO standards when asking for help.