I have an issue with SQL IN query I'm storing multiple employees id in a table separated with comma...











up vote
0
down vote

favorite













This question already has an answer here:




  • Is storing a delimited list in a database column really that bad?

    10 answers




I have an issue with SQL IN query: I'm storing multiple employee IDs in a table, separated with commas for each task. When I try to fetch a task with an IN query, I'm not getting the row which contains the employee IDs.



My query is:



select 
t.*,
e.emp_name,
d.department_name
from
task as t
LEFT JOIN employee as e on(e.emp_id=t.assign_to)
LEFT JOIN department as d on(d.depart_id=e.depart_id)
where
t.task_status='PENDING'
AND t.created_by!='31'
AND t.assign_to IN ('31')
order by
t.task_id DESC


The stored value in database










share|improve this question















marked as duplicate by Madhur Bhaiya, u_mulder php
Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 12 at 6:55


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















    up vote
    0
    down vote

    favorite













    This question already has an answer here:




    • Is storing a delimited list in a database column really that bad?

      10 answers




    I have an issue with SQL IN query: I'm storing multiple employee IDs in a table, separated with commas for each task. When I try to fetch a task with an IN query, I'm not getting the row which contains the employee IDs.



    My query is:



    select 
    t.*,
    e.emp_name,
    d.department_name
    from
    task as t
    LEFT JOIN employee as e on(e.emp_id=t.assign_to)
    LEFT JOIN department as d on(d.depart_id=e.depart_id)
    where
    t.task_status='PENDING'
    AND t.created_by!='31'
    AND t.assign_to IN ('31')
    order by
    t.task_id DESC


    The stored value in database










    share|improve this question















    marked as duplicate by Madhur Bhaiya, u_mulder php
    Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 12 at 6:55


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite












      This question already has an answer here:




      • Is storing a delimited list in a database column really that bad?

        10 answers




      I have an issue with SQL IN query: I'm storing multiple employee IDs in a table, separated with commas for each task. When I try to fetch a task with an IN query, I'm not getting the row which contains the employee IDs.



      My query is:



      select 
      t.*,
      e.emp_name,
      d.department_name
      from
      task as t
      LEFT JOIN employee as e on(e.emp_id=t.assign_to)
      LEFT JOIN department as d on(d.depart_id=e.depart_id)
      where
      t.task_status='PENDING'
      AND t.created_by!='31'
      AND t.assign_to IN ('31')
      order by
      t.task_id DESC


      The stored value in database










      share|improve this question
















      This question already has an answer here:




      • Is storing a delimited list in a database column really that bad?

        10 answers




      I have an issue with SQL IN query: I'm storing multiple employee IDs in a table, separated with commas for each task. When I try to fetch a task with an IN query, I'm not getting the row which contains the employee IDs.



      My query is:



      select 
      t.*,
      e.emp_name,
      d.department_name
      from
      task as t
      LEFT JOIN employee as e on(e.emp_id=t.assign_to)
      LEFT JOIN department as d on(d.depart_id=e.depart_id)
      where
      t.task_status='PENDING'
      AND t.created_by!='31'
      AND t.assign_to IN ('31')
      order by
      t.task_id DESC


      The stored value in database





      This question already has an answer here:




      • Is storing a delimited list in a database column really that bad?

        10 answers








      php mysql sql phpmyadmin






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 8:20









      Joe McMahon

      2,1871225




      2,1871225










      asked Nov 12 at 6:48









      Madhukant Tiwari

      1




      1




      marked as duplicate by Madhur Bhaiya, u_mulder php
      Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 12 at 6:55


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by Madhur Bhaiya, u_mulder php
      Users with the  php badge can single-handedly close php questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 12 at 6:55


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          IN doesn't work like that



          Example if your data looks like:



          ManagerName, ManagerOf
          'John', 'Steve,Sarah,Dave'


          You can't do:



          SELECT * FROM managers WHERE 'sarah' IN ManagerOf


          IN is best conceived as an extension of OR:



          SELECT * FROM managers WHERE managerof IN ('Sarah','Steve')
          --is the same as:
          SELECT * FROM managers WHERE
          managerof = 'Sarah' OR
          managerof = 'Steve'


          There would be as many OR clauses as there are items in the IN list.



          Hopefully this shows you why the database doesn't return you any results.. Because a value of Steve,Sarah,Dave is not equal to either Sarah or Steve. The database doesn't look at the commas and say "oh, that's a list" - it's just a single string of characters that happens to have a comma character every now and then



          There are nasty quick hacks to so-so achieve what you want, using LIKE and string concat but they aren't worthy of an answer, to be honest



          You need to change your database structure to include a new table that tracks the task id and the employee(s) id it is/was assigned to. After doing that, you'll be able to use IN on the employee id column as you're expecting to with this query






          share|improve this answer






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            IN doesn't work like that



            Example if your data looks like:



            ManagerName, ManagerOf
            'John', 'Steve,Sarah,Dave'


            You can't do:



            SELECT * FROM managers WHERE 'sarah' IN ManagerOf


            IN is best conceived as an extension of OR:



            SELECT * FROM managers WHERE managerof IN ('Sarah','Steve')
            --is the same as:
            SELECT * FROM managers WHERE
            managerof = 'Sarah' OR
            managerof = 'Steve'


            There would be as many OR clauses as there are items in the IN list.



            Hopefully this shows you why the database doesn't return you any results.. Because a value of Steve,Sarah,Dave is not equal to either Sarah or Steve. The database doesn't look at the commas and say "oh, that's a list" - it's just a single string of characters that happens to have a comma character every now and then



            There are nasty quick hacks to so-so achieve what you want, using LIKE and string concat but they aren't worthy of an answer, to be honest



            You need to change your database structure to include a new table that tracks the task id and the employee(s) id it is/was assigned to. After doing that, you'll be able to use IN on the employee id column as you're expecting to with this query






            share|improve this answer



























              up vote
              1
              down vote













              IN doesn't work like that



              Example if your data looks like:



              ManagerName, ManagerOf
              'John', 'Steve,Sarah,Dave'


              You can't do:



              SELECT * FROM managers WHERE 'sarah' IN ManagerOf


              IN is best conceived as an extension of OR:



              SELECT * FROM managers WHERE managerof IN ('Sarah','Steve')
              --is the same as:
              SELECT * FROM managers WHERE
              managerof = 'Sarah' OR
              managerof = 'Steve'


              There would be as many OR clauses as there are items in the IN list.



              Hopefully this shows you why the database doesn't return you any results.. Because a value of Steve,Sarah,Dave is not equal to either Sarah or Steve. The database doesn't look at the commas and say "oh, that's a list" - it's just a single string of characters that happens to have a comma character every now and then



              There are nasty quick hacks to so-so achieve what you want, using LIKE and string concat but they aren't worthy of an answer, to be honest



              You need to change your database structure to include a new table that tracks the task id and the employee(s) id it is/was assigned to. After doing that, you'll be able to use IN on the employee id column as you're expecting to with this query






              share|improve this answer

























                up vote
                1
                down vote










                up vote
                1
                down vote









                IN doesn't work like that



                Example if your data looks like:



                ManagerName, ManagerOf
                'John', 'Steve,Sarah,Dave'


                You can't do:



                SELECT * FROM managers WHERE 'sarah' IN ManagerOf


                IN is best conceived as an extension of OR:



                SELECT * FROM managers WHERE managerof IN ('Sarah','Steve')
                --is the same as:
                SELECT * FROM managers WHERE
                managerof = 'Sarah' OR
                managerof = 'Steve'


                There would be as many OR clauses as there are items in the IN list.



                Hopefully this shows you why the database doesn't return you any results.. Because a value of Steve,Sarah,Dave is not equal to either Sarah or Steve. The database doesn't look at the commas and say "oh, that's a list" - it's just a single string of characters that happens to have a comma character every now and then



                There are nasty quick hacks to so-so achieve what you want, using LIKE and string concat but they aren't worthy of an answer, to be honest



                You need to change your database structure to include a new table that tracks the task id and the employee(s) id it is/was assigned to. After doing that, you'll be able to use IN on the employee id column as you're expecting to with this query






                share|improve this answer














                IN doesn't work like that



                Example if your data looks like:



                ManagerName, ManagerOf
                'John', 'Steve,Sarah,Dave'


                You can't do:



                SELECT * FROM managers WHERE 'sarah' IN ManagerOf


                IN is best conceived as an extension of OR:



                SELECT * FROM managers WHERE managerof IN ('Sarah','Steve')
                --is the same as:
                SELECT * FROM managers WHERE
                managerof = 'Sarah' OR
                managerof = 'Steve'


                There would be as many OR clauses as there are items in the IN list.



                Hopefully this shows you why the database doesn't return you any results.. Because a value of Steve,Sarah,Dave is not equal to either Sarah or Steve. The database doesn't look at the commas and say "oh, that's a list" - it's just a single string of characters that happens to have a comma character every now and then



                There are nasty quick hacks to so-so achieve what you want, using LIKE and string concat but they aren't worthy of an answer, to be honest



                You need to change your database structure to include a new table that tracks the task id and the employee(s) id it is/was assigned to. After doing that, you'll be able to use IN on the employee id column as you're expecting to with this query







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 12 at 7:54

























                answered Nov 12 at 7:41









                Caius Jard

                9,01611136




                9,01611136















                    Popular posts from this blog

                    鏡平學校

                    ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

                    Why https connections are so slow when debugging (stepping over) in Java?