Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why won't this sql statement work???

Status
Not open for further replies.

sd0t1

IS-IT--Management
Mar 14, 2007
131
US
I doesn't give an error, it just does not return any rows.

Here is the search I'm doing.
I have an 'Offender' table that has id, dob, ssn, first, last.
I have a 'Schedule' table that has (Offender.id)oid, case#, (and other information related to that case)

My search is a detailed search that allows a user to search by first, last, ssn or dob (any will work).
The search checks the schedule table to find if that offender has any cases in the schedule table.
But because the search criteria (first, last, dob, ssn) are in the offender table I use a subquery in the WHERE clause to find the offender.id to match against the schedule.oid.

SELECT offender.id, offender.f_name, offender.l_name, offender.m_initial, offender.dob, schedule.oid, schedule.case_no, schedule.pid FROM offender JOIN schedule ON offender.id = schedule.oid WHERE schedule.oid IN (SELECT offender.id FROM offender WHERE l_name LIKE '$l_name%' AND f_name LIKE '$f_name%' AND ssn LIKE '$ssn%' AND dob LIKE '$dob%')
 
I found my error, thanks for your help anyway.
Sorry for any inconvenience.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top