1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Question on how to use OR in a Select statement with where clause

Discussion in 'PHP' started by newphpcoder, Feb 15, 2012.

  1. newphpcoder

    newphpcoder New Member

    Joined:
    Sep 24, 2010
    Messages:
    101
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Web Programmer
    Location:
    Philippines
    Hi...
    I just want to know how can I use OR in my select statement to check if the DATE is equal in NRS table or Reg Att table.
    Here is my real code without or to check if the DATE is in NRS not in regatt.
    here is my code now:
    in this code it works because the data is present in reg_att table
    Code:
    SELECT em.EMP_NO, p.EMP_ID, CONCAT(LNAME, ', ', FNAME, ' ', MI, '.') AS FULLNAME, DATE(a.LOGOUT) AS DATE_DTR, LOGIN AS min_dtr, LOGOUT AS max_dtr FROM hris.personal p, payroll.reg_att a, hris.employment em WHERE DATE(a.LOGOUT) = '2011-12-19' AND p.EMP_ID = '000252' and em.EMP_ID = '000252' AND em.EMP_NO = a.EMP_NO
    
    now that is possible that data is not present in reg_att but possible present in nrs table.
    and I tried this:
    Code:
    SELECT em.EMP_NO, p.EMP_ID, CONCAT(LNAME, ', ', FNAME, ' ', MI, '.') AS FULLNAME, DATE(a.LOGOUT) OR DATE(n.TIME_OUT) AS DATE_DTR, a.LOGIN OR n.TIME_IN AS min_dtr, LOGOUT OR TIME_OUT AS max_dtr FROM payroll.nrs n,hris.personal p, payroll.reg_att a, hris.employment em WHERE DATE(a.LOGOUT) OR DATE(n.TIME_OUT) = '2011-12-19' AND p.EMP_ID = '000252' and em.EMP_ID = '000252' AND em.EMP_NO = a.EMP_NO OR em.EMP_NO = n.EMP_NO;
    
    but it did not work.
    Thank you
     
  2. pein87

    pein87 New Member

    Joined:
    Aug 6, 2010
    Messages:
    173
    Likes Received:
    47
    Trophy Points:
    0
    Occupation:
    Web Dev
    Location:
    Limbo
    If your checking equivalence use <> instead of = . Each one has its own usages. = is for numbers and <> is for text.
     
    Last edited: Mar 3, 2012

Share This Page