Mysql custom where condition

My table is :

I want to select records who all are fail(result=0) but except who has same course_id result is 1.

For example look my table there are two rows have result=0 but student_id=1 has another row with result=1 so i want skip this record.

Sorry for confusing you.I hope my expecting output explains clearly what I want.

Expecting output is :

2 | 1 | 0

Answers


Try this

SELECT student_id, course_id, result FROM tbl WHERE result = 0 
AND student_id NOT IN (SELECT student_id FROM table WHERE result =1 
                                      and course_id = tbl.course_id )

Above we are selecting all records that have a result =0 only if the student_id and course_id is not found in the sub query with a result=1


Need Your Help

How do you know what encoding the user is inputing into the browser?

php html encoding utf-8

I read Joel's article about character sets and so I'm taking his advice to use UTF-8 on my web page and in my database. What I can't understand is what to do with user input. As Joel says, "It do...

Mark points on contour line using OpenCV

c++ opencv image-processing contour edge-detection

I want to make set of points in similar distance on a edge line of plant leaf (as shown in the below image). I want to make the red coloured small square on the edge line of the leaf.I store the se...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.