Simple Solution MSSQL Server
\n\n\nIn this exercies we need to find all patiants who have Type I Diabetes. \nType I Diabetes always starts with DIAB1 prefix.\n\nSolution:\n\n\nselect *\nfro
\n\n\nIn this exercies we need to find all patiants who have Type I Diabetes. \nType I Diabetes always starts with **DIAB1** prefix.\n\n***Solution:***\n\n```\nselect *\nfrom Patients\nwhere conditions like \'% DIAB1%\'\nor conditions like \'DIAB1%\'\n```\n\nThe **easiest** way here is using ```LIKE ``` operator.\n\nIn first two rows we simply select all records from table **Patients**.\n\n```\nselect *\nfrom Patients\n```\n\nNow we need to filter our records.\nWe use ```LIKE``` operator.\nThe ```LIKE``` operator is used in a ```WHERE``` clause to search for a specified pattern in a column.\n\nThere are two wildcards often used in conjunction with the ```LIKE``` operator:\n\n The percent sign % represents zero, one, or multiple characters\n The underscore sign _ represents one, single character\n\nIN our case we use only % charachter\n\n```\nwhere conditions like \'% DIAB1%\'\nor conditions like \'DIAB1%\'\n```\n\nSo this one ```where conditions like \'% DIAB1%\'``` means that we are looking for all conditions(this is column name) that are satisfying 2 things:\n\n1.Before **"DIAB1"** will be *1 white space* and before whitespace will be *0 or more* charachters. (**% DIAB1** - first part).\n2.And after **"DIAB1"** will be *0 or more* charachters. (**DIAB1%** - second part). \n\nIn the next condition ```or conditions like \'DIAB1%\'``` I used the same logic. There are two conditions in this one:\n1. String always starts with **\'DIAB1\'**. (**DIAB1** - first part)\n2 .There can be 0 or more chars after **\'DIAB1\'**. (**DIAB1%** - second part)\n\n**Question:**\n1. Why we need both \n```\nwhere conditions like \'% DIAB1%\'\nor conditions like \'DIAB1%\'\n```\n\n**Answer**\nIn first one (```where conditions like \'% DIAB1%\'```): we choose "DIabetes" ike a **second, third, etc.** condition \n\nFor example: \nPatients table:\n+------------+--------------+--------------+\n| patient_id | patient_name | conditions   |\n+------------+--------------+--------------+\n| 1          | Daniel       | YFEV COUGH   |\n**| 3          | Bob          | DIAB100 MYOP |**\n**| 4          | George       | ACNE DIAB100 |**\n\nThis one(```where conditions like \'% DIAB1%\'```) will choose **"George"** (*patientid: 4*), because he has "ACNE **DIAB100**" so Diabetes comes like a **second** condition here. But this clause **will not** choose "Bob" (*patientid: 3*) because in **Bobs** case Diabetes comes like a **first** condition.\n\nAnd **for this purposes** we need clause **or**:\n```or conditions like \'DIAB1%\'```\nThis clause **will choose Bob** but **not George** because it chooses every patient who has Diabetes like a **first** condition.\n\n\n__________________________________________________________________\n\nWrite me if you have any questioons :) .\n\n\n.\n
['MySQL', 'MS SQL Server']