Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameters in a SQL query

I am passing where clause parameter values from a program however when I am sending at least one one value I get the result however if I am sending all parameters as null no output is coming, i want a query such that if all parameters are sent as null will display all the records in the database

following is the query which retrieves values if one condition is satisfied

SELECT * 
  FROM STUDENT
  LEFT JOIN COURSE
    ON STUDENT.COURSE_ID = COURSE.COURSE_ID
 WHERE STUDENT.STD_ID = null
   OR STUDENT.STD_NAME = null
   OR STUDENT.STD_START_DATE = null
   OR STUDENT.STD_END_DATE = null
   OR STUDENT.STD_GENDER = null
   OR STUDENT.COURSE_ID = null;
like image 617
user2218550 Avatar asked Jul 13 '26 00:07

user2218550


1 Answers

Try below,

SELECT *
FROM   STUDENT
       LEFT JOIN COURSE
              ON STUDENT.COURSE_ID = COURSE.COURSE_ID
WHERE  STUDENT.STD_ID IS NULL
        OR STUDENT.STD_NAME IS NULL
        OR STUDENT.STD_START_DATE IS NULL
        OR STUDENT.STD_END_DATE IS NULL
        OR STUDENT.STD_GENDER IS NULL
        OR STUDENT.COURSE_ID IS NULL 
like image 76
psmydin Avatar answered Jul 15 '26 13:07

psmydin