Lesson 03 (Filter Data)

Filter Data with Where clause-

Syntax-

select

            column1, column2……………

from

            table1, table2……………………

where condition

Data Filter करने के लिए हमें कुछ Conditional & Logical Operators का प्रयोग करना होता है -

Conditional Operator

=        Equal            बराबर 

!= or <>    Not Equal        बराबर नहीं 

<        Less Than        बड़ा 

>        More Than        छोटा 

>=         More than Equal    बड़ा या बराबर 

<=         Less than Equal    छोटा या बराबर 


Logial Operator 


And        और 

or        या 


  1. ऐसी लिस्ट तैयार करो जिसमें faculty id, name. qualification प्रदर्शित हों जिनकी qualification B.Tech हो 

select fid, fname from faculty where qualification =’B.Tech.’;


  1. faculty details पता करो जिनकी qualification Ph.D. नहीं हो 

Select * from faculty where qualification <>’Ph.D.’;


  1. जिन छात्रों की branch ‘IT’ & Marks 80 से कम हों उनके नाम प्रदर्शित करो 

select sname from student where branch=’IT’ and marks<80;


  1. जिन छात्रों की branch ‘IT’ or ‘ECE’ हो उन छात्रों के नाम प्रदर्शित करो 

select sname from student where branch=’IT’ or branch=’ECE’;



IN and NOT IN Operator                           

Syntax-

select

    column1, column2…..

from

    table1, table2….

where (expr|column_1) IN(value1, value2…);


1- Faculty Name प्रदर्शित करो जिनका department 1 या 3 हो 


select fname from faculty where deptid =1 or deptid=3;

select fname from faculty where deptid IN(1,3);


2- जिन faculty की qualification B.Tech., या Ph.D है उनकी details प्रदर्शित करो 

select * from faculty where qualification IN(‘B. Tech’, ‘Ph.D’);


3- जिनकी Student की branch  or IT नहीं है उनकी detail प्रदर्शित करो |

select * from student where branch NOT IN (‘IT’, ‘CSE’);


BETWEEN and  NOT BETWEEN Operator

Between operator is used to filter data and allows to specify range of values to test.

Syntax-

select 

    column1, column2,.....

from 

    table1, table2……

where (expr|column_1) BETWEEN begin AND end;


  • NOT BETWEEN IS OPPOSITE


1- ऐसे छात्रों की सूची प्रदर्शित करो जिनके marks 60 and 90 के बीच में हों |

select * from student where marks BETWEEN 60 and 90;


2- ऐसे छात्रों की जानकारी प्रदर्शित करो जिनके marks 50 और 60 के बीच में न हों |

select * from student where marks NOT BETWEEN 50 and 60;


LIMIT AND IS NULL clause

LIMIT is used to constrain the number of rows returned by the select statement - अर्थात किन्ही बिशेष संख्या वाली row को प्रदर्शित करता है |

Syntax-

select

    column1, column2,...................

from 

    table1, table2………………….

LIMIT offset, count;


offset- start row no, 1st row index no 0 

count- no. of rows


FETCH first N rows in Mysql

select 

    column1, column2….

from 

    table1, table2……..

LIMIT N


IS NULL OPERATOR 

IS NULL operator is used to check wheather is NULL or not.

opposite of IS NULL is IS NOT NULL.


  1. faculty table में से पहले 4 Record प्रदर्शित |

select * from faculty LIMIT 4;

select * from faculty LIMIT 0,4;


  1. faculty table में से 2nd and 3rd रिकॉर्ड प्रदर्शित करो |

select * from faculty LIMIT 1,2;


  1. student table में से ऐसे छात्रों की जानकारी दिखाओ जिनकी branch रिक्त है |

select * from student where branch IS NULL;


  1. student table में से ऐसे छात्रों के नाम  प्रदर्शित करो जिनकी branch रिक्त नहीं है |

select sname from student where branch IS NOT NULL;


LIKE OPERATOR 

To seach a pattern like A* etc. and wildcard character - %, underscore (_)


Syntax

select column from table where condition LIKE ‘pattern’;


  1. faculty table में से ऐसे रिकॉर्ड प्रदर्शित करो जिनके नाम ‘A’ से शुरू होते हैं |

select * from faculty where fname LIKE ‘A%’;


  1. faculty table में से ऐसे नामों की लिस्ट प्रदर्शित करो जिनके नाम का अंतिम अक्षर ‘N’ हो |

select fname from faculty where fname LIKE ‘%N’

  1. student table में से ऐसे छात्रों के नाम और मार्क्स प्रदर्शित करो जिनके नाम का दूसरा अक्षर ‘A’ है |

select sname, marks from student where sname LIKE ‘_A%’;


  1. student table में से ऐसे छात्रों के नाम प्रदर्शित करो जिनका नाम ‘P’ से शुरू होता हो और उनके नाम में 5 ही अक्षर हों|

select sname, marks from student where sname LIKE ‘P_ _ _ _ ’ ;


  1. faculty table में से ऐसे लोगों की जानकारी दिखाओ जिनके नाम का अंतिम अक्षर ‘N’ न हो |

select * from faculty where fname NOT LIKE ‘%N’;


  1. student table में से ऐसे छात्रों की जानकारी प्रदर्शित करो जिनके नाम का दूसरा अक्षर ‘A’ न हो |

select * from student where sname NOT LIKE ‘_A%’;

Comments

Popular posts from this blog

Lesson 07 (Primary Key & Foreign Key)

Lesson 05(Modifying Data)