• saravanatn - Wednesday, December 6, 2017 1:00 AM

    >>In the below table records [sic] are grouped by ID column. If the count for ID is greater than 1 then remove the records [sic] which are having 'NULL" values in any of the name ,city, place columns and remaining columns need to be fetched. If the count for ID=1 even if we have NULL values on any of the columns then include that records [sic] in the output results. <<

    Can you please buy read and study a book on RDBMS and SQL? There is no such thing as a generic "id" in RDBMS. It has to be the identifier of something in particular to be valid. Then on top of that, and identifier can never be a numeric because you don't do math on it.

    You might want to read a book on basic data modeling. Things like "city" are too vague generic to be valid column names. They need to have what the ISO 11179 people call "attribute property" to be valid. And you're "name" is one of those attribute properties; it has to be the name of something.

    A table by definition, must have a primary key. But this deck of punch cards doesn't have a key and can never have any keys! Let's at least get the column names and how many datatypes correct. I picked a length of 35 for the names based on the International Postal Union requirements for mailing labels. I'm willing to bet that you made up the length of 100, with no research whatsoever. This is not how to be a database professional

    CREATE TABLE Details
    (detail_id CHAR(3)NOT NULL PRIMARY KEY,
    something_name VARCHAR(35),
    city_name VARCHAR(35),
    place_name VARCHAR(35)
    );

    If you have valid data, then you should be able to use the current table constructor insertion syntax. That would look like this. People who think in sets instead of in punchcards really like it. It lets the optimizer do some things, instead of forcing a sequential insertion. But you're trying put garbage in a table. To do this, you of course have to screwup the DDL for that table you have valid data, then you should be able to use the current table constructor insertion syntax. That would look like this. People who think in sets instead of in punchcards really like it. It lets the optimizer do some things, instead of forcing a sequential insertion. But you're trying put garbage in a table. To do this, you of course have to screwup the DDL for that table

    INSERT INTO Details
    VALUES
    (1, 'sara', 'chennai', 't.nagar'),
    (1, NULL, NULL, NULL), -- dup key
    (1, 'sara', 'chennai', 't.nagar'), --- dup row!

    (2, 'sara', 'chennai', 't.nagar'),
    (2, NULL, NULL, NULL), ---dup key

    (3, 'sara', 'chennai', 't.nagar'),

    (4, NULL, NULL, NULL),

    (5, 'raj', 'vellore', 'kodambakkam'),
    (5, 'raj', 'vellore', NULL); ---dup key

    What are you trying to actually do? My first impulse is that you need to have stored procedure that does the row update for Details.

    CREATE PROCEDURE Fill_Details
    (@in_detail_id CHAR(3), @in_something_name VARCHAR(35),
    @in_city_name VARCHAR(35), @in_place_name )
    BEGIN
    UPDATE Details
    SET something_name = COALESCE(something_name, @in_something_name),
      city_name = COALESCE (city_name, @in_city_name),
      place_name = COALESCE (place_name, @in_place_name)
    WHERE detail_id = @in_detail_id;
    -- insert new row, if it does not exist
    END;

    ]What are you trying to actually do? My first impulse is that you need to have stored procedure that does the row update for Details.CREATE CREATE PROCEDURE Fill_Details(@in_detail_id CHAR(3), @in_something_name VARCHAR(35), @in_city_name VARCHAR(35), @in_place_name )
    BEGIN
    UPDATE Details
    SET something_name = COALESCE(something_name, @in_something_name),  
     city_name = COALESCE (city_name, @in_city_name),
     place_name = COALESCE (place_name, @in_place_name
    )WHERE detail_id = @in_detail_id;-- insert new row, if it does not exist
    END;

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