Modeling Optional Column












0















I've got an optional column (residential) in one of my tables that is giving me trouble. If a Licensee intends to work w/ residential customers, they need to take an additional course (course_topic_code C):



CREATE TABLE Licensees (
license_num INTEGER PRIMARY KEY,
license_level VARCHAR(50) NOT NULL,
residential BOOLEAN
);

INSERT INTO Licensees VALUES
(123, 'Salesperson', NULL),
(234, 'Salesperson', TRUE),
(567, 'Salesperson', FALSE);


CREATE TABLE Course_Requirements (
PRIMARY KEY (license_level, residential, course_topic_code),
license_level VARCHAR(50) NOT NULL,
residential BOOLEAN,
course_topic_code CHARACTER NOT NULL,
required_minutes INTEGER NOT NULL
);

INSERT INTO Course_Requirements VALUES
('Salesperson', true, 'C', 90),
('Salesperson', true, 'A', 180),
('Salesperson', false, 'A', 180),
('Broker', true, 'C', 90),
('Broker', true, 'A', 180),
('Broker', false, 'A', 180);


The trouble is, it's valid for me to not know whether a Licensee intends to service residential customers. If the column is true they're required to take that course, but if it is false or null they're not required. This is the query I've come up with to see required courses for each Licensee:



select l.license_num, cr.course_topic_code, cr.required_minutes
from Course_Requirements cr
join Licensees l on cr.license_level = l.license_level
and cr.residential = l.residential;


As you can see, the licensee w/ NULL for residential has no required courses:



567;"A";180
234;"C";90
234;"A";180


I might be able to devise a query that will give me what I want, but I feel that I might be modeling things incorrectly. I generally try to avoid nullable fields, but in this situation it seems appropriate. Is there a better way to model this?










share|improve this question














bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    0















    I've got an optional column (residential) in one of my tables that is giving me trouble. If a Licensee intends to work w/ residential customers, they need to take an additional course (course_topic_code C):



    CREATE TABLE Licensees (
    license_num INTEGER PRIMARY KEY,
    license_level VARCHAR(50) NOT NULL,
    residential BOOLEAN
    );

    INSERT INTO Licensees VALUES
    (123, 'Salesperson', NULL),
    (234, 'Salesperson', TRUE),
    (567, 'Salesperson', FALSE);


    CREATE TABLE Course_Requirements (
    PRIMARY KEY (license_level, residential, course_topic_code),
    license_level VARCHAR(50) NOT NULL,
    residential BOOLEAN,
    course_topic_code CHARACTER NOT NULL,
    required_minutes INTEGER NOT NULL
    );

    INSERT INTO Course_Requirements VALUES
    ('Salesperson', true, 'C', 90),
    ('Salesperson', true, 'A', 180),
    ('Salesperson', false, 'A', 180),
    ('Broker', true, 'C', 90),
    ('Broker', true, 'A', 180),
    ('Broker', false, 'A', 180);


    The trouble is, it's valid for me to not know whether a Licensee intends to service residential customers. If the column is true they're required to take that course, but if it is false or null they're not required. This is the query I've come up with to see required courses for each Licensee:



    select l.license_num, cr.course_topic_code, cr.required_minutes
    from Course_Requirements cr
    join Licensees l on cr.license_level = l.license_level
    and cr.residential = l.residential;


    As you can see, the licensee w/ NULL for residential has no required courses:



    567;"A";180
    234;"C";90
    234;"A";180


    I might be able to devise a query that will give me what I want, but I feel that I might be modeling things incorrectly. I generally try to avoid nullable fields, but in this situation it seems appropriate. Is there a better way to model this?










    share|improve this question














    bumped to the homepage by Community 10 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      0












      0








      0








      I've got an optional column (residential) in one of my tables that is giving me trouble. If a Licensee intends to work w/ residential customers, they need to take an additional course (course_topic_code C):



      CREATE TABLE Licensees (
      license_num INTEGER PRIMARY KEY,
      license_level VARCHAR(50) NOT NULL,
      residential BOOLEAN
      );

      INSERT INTO Licensees VALUES
      (123, 'Salesperson', NULL),
      (234, 'Salesperson', TRUE),
      (567, 'Salesperson', FALSE);


      CREATE TABLE Course_Requirements (
      PRIMARY KEY (license_level, residential, course_topic_code),
      license_level VARCHAR(50) NOT NULL,
      residential BOOLEAN,
      course_topic_code CHARACTER NOT NULL,
      required_minutes INTEGER NOT NULL
      );

      INSERT INTO Course_Requirements VALUES
      ('Salesperson', true, 'C', 90),
      ('Salesperson', true, 'A', 180),
      ('Salesperson', false, 'A', 180),
      ('Broker', true, 'C', 90),
      ('Broker', true, 'A', 180),
      ('Broker', false, 'A', 180);


      The trouble is, it's valid for me to not know whether a Licensee intends to service residential customers. If the column is true they're required to take that course, but if it is false or null they're not required. This is the query I've come up with to see required courses for each Licensee:



      select l.license_num, cr.course_topic_code, cr.required_minutes
      from Course_Requirements cr
      join Licensees l on cr.license_level = l.license_level
      and cr.residential = l.residential;


      As you can see, the licensee w/ NULL for residential has no required courses:



      567;"A";180
      234;"C";90
      234;"A";180


      I might be able to devise a query that will give me what I want, but I feel that I might be modeling things incorrectly. I generally try to avoid nullable fields, but in this situation it seems appropriate. Is there a better way to model this?










      share|improve this question














      I've got an optional column (residential) in one of my tables that is giving me trouble. If a Licensee intends to work w/ residential customers, they need to take an additional course (course_topic_code C):



      CREATE TABLE Licensees (
      license_num INTEGER PRIMARY KEY,
      license_level VARCHAR(50) NOT NULL,
      residential BOOLEAN
      );

      INSERT INTO Licensees VALUES
      (123, 'Salesperson', NULL),
      (234, 'Salesperson', TRUE),
      (567, 'Salesperson', FALSE);


      CREATE TABLE Course_Requirements (
      PRIMARY KEY (license_level, residential, course_topic_code),
      license_level VARCHAR(50) NOT NULL,
      residential BOOLEAN,
      course_topic_code CHARACTER NOT NULL,
      required_minutes INTEGER NOT NULL
      );

      INSERT INTO Course_Requirements VALUES
      ('Salesperson', true, 'C', 90),
      ('Salesperson', true, 'A', 180),
      ('Salesperson', false, 'A', 180),
      ('Broker', true, 'C', 90),
      ('Broker', true, 'A', 180),
      ('Broker', false, 'A', 180);


      The trouble is, it's valid for me to not know whether a Licensee intends to service residential customers. If the column is true they're required to take that course, but if it is false or null they're not required. This is the query I've come up with to see required courses for each Licensee:



      select l.license_num, cr.course_topic_code, cr.required_minutes
      from Course_Requirements cr
      join Licensees l on cr.license_level = l.license_level
      and cr.residential = l.residential;


      As you can see, the licensee w/ NULL for residential has no required courses:



      567;"A";180
      234;"C";90
      234;"A";180


      I might be able to devise a query that will give me what I want, but I feel that I might be modeling things incorrectly. I generally try to avoid nullable fields, but in this situation it seems appropriate. Is there a better way to model this?







      database-design






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jul 23 '16 at 13:30









      Joe SnikerisJoe Snikeris

      1467




      1467





      bumped to the homepage by Community 10 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 10 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          question is not clear to me but this might be what you are looking for



          select l.license_num, cr.course_topic_code, cr.required_minutes
          from Course_Requirements cr
          join Licensees l on cr.license_level = l.license_level
          and cr.residential = isnull(l.residential,1);





          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "182"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f144719%2fmodeling-optional-column%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            question is not clear to me but this might be what you are looking for



            select l.license_num, cr.course_topic_code, cr.required_minutes
            from Course_Requirements cr
            join Licensees l on cr.license_level = l.license_level
            and cr.residential = isnull(l.residential,1);





            share|improve this answer




























              0














              question is not clear to me but this might be what you are looking for



              select l.license_num, cr.course_topic_code, cr.required_minutes
              from Course_Requirements cr
              join Licensees l on cr.license_level = l.license_level
              and cr.residential = isnull(l.residential,1);





              share|improve this answer


























                0












                0








                0







                question is not clear to me but this might be what you are looking for



                select l.license_num, cr.course_topic_code, cr.required_minutes
                from Course_Requirements cr
                join Licensees l on cr.license_level = l.license_level
                and cr.residential = isnull(l.residential,1);





                share|improve this answer













                question is not clear to me but this might be what you are looking for



                select l.license_num, cr.course_topic_code, cr.required_minutes
                from Course_Requirements cr
                join Licensees l on cr.license_level = l.license_level
                and cr.residential = isnull(l.residential,1);






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jul 23 '16 at 14:07









                paparazzopaparazzo

                4,6141230




                4,6141230






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Database Administrators Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f144719%2fmodeling-optional-column%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Liste der Baudenkmale in Friedland (Mecklenburg)

                    Single-Malt-Whisky

                    Czorneboh