Click to See Complete Forum and Search --> : [RESOLVED] LIKE condition/Oracle


rbragg
10-10-2007, 10:24 AM
I have this in my page:
SELECT *
FROM schema.call, schema.student, schema.status, schema.hall, schema.room
WHERE call.s_num = student.s_num
AND call.status_num = status.status_num
AND call.hall_num = hall.hall_num
AND call.room_num = room.room_num
AND student.s_first LIKE '%" . $gotStudent . "%' OR student.s_last LIKE '%" . $gotStudent . "%';
No matter what $gotStudent is I don't get results even if I know there are some. I have used SQL Plus for testing. If I enter a literal query wishing to return someone with the last name "Foster":
SELECT *
FROM schema.call, schema.student, schema.status, schema.hall, schema.room
WHERE call.s_num = student.s_num
AND call.status_num = status.status_num
AND call.hall_num = hall.hall_num
AND call.room_num = room.room_num
AND student.s_first LIKE '%fos%' OR student.s_last LIKE '%fos%';
I get "no rows selected".

rbragg
10-10-2007, 11:12 AM
Duh - case sensitive. If I would have searched for "Fos", I would have found a match. However, NOW I am getting redundant data with this query. I have one student with "Fos" in their name and I'm getting thousands of records. Something is obviously up with my query.

bubbisthedog
10-10-2007, 11:14 AM
This maybe?

AND (LOWER(student.s_first) LIKE LOWER('%" . $gotStudent . "%') OR LOWER(student.s_last) LIKE LOWER('%" . $gotStudent . "%'));

rbragg
10-10-2007, 11:39 AM
Thanks for the reply. :) Yes, I should have marked this thread as resolved. A colleague here suggested the same thing. Also, I need to do another query to cut out the redundant results.