I've got three tables, Case, Violator, Alias
Case is a court police case
Violator is the person
Alias is different names (aliases) that person has.
Here's my Query:
Expand|Select|Wrap|Line Numbers
- SELECT
- c.id ,
- c.caseNumber ,
- v.lastName ,
- v.firstName ,
- a.firstName AS aliasFirstName,
- a.lastName AS aliasLastName,
- v.driverLicenseNumber ,
- v.dateOfBirth ,
- t.courtDate ,
- c.status
- FROM
- `case` as c LEFT JOIN trial as t ON c.id = t.caseID,
- violator as v LEFT JOIN alias as a ON v.id = a.violatorID
- WHERE
- c.violatorID = v.id AND
- ( c.status IN ('CONT','ARR','DE','FTAP','OJW','PRO','STAY','WRNT'))
- ORDER BY 1 DESC;
- //Here's some test results from fake data, some fields are cut off because of no room.
- +-----+------------+-----------+-------------+----------------+---------------+
- | id | caseNumber | lastName | firstName | aliasFirstName | aliasLastName
- +-----+------------+-----------+-------------+----------------+---------------+
- | 117 | A001 | DOE | JOHN | NULL | NULL
- | 116 | 07PA36503 | AVENT | CHRISTOPHER | NULL
- | 115 | 07PA33856 | APPLEBY | KENT | NULL
- | 114 | 07PA36620 | ANDERSON | JOSHUA | Josh
- | 114 | 07PA36620 | ANDERSON | JOSHUA | Joshi
- | 113 | 07PA35300 | ADNDERSON | DONALD | NULL | NULL
- | 112 | 07PA36487 | AKHTAR | NASER | NULL | NULL
- | 111 | 07PA36488 | AKHTAR | NASER | NULL | NULL
- | 110 | CA0003 | ARANJUEZ | ALAN | NULL | NULL
- | 109 | CA0001 | CARINOS | JOHNY | Jimmy | Car
- | 106 | CA0002 | MILLS | CORRINE | NULL | NULL
- +-----+------------+-----------+-------------+----------------+---------------+
- //expect result is for the second caseID 114 to not be displayed.
How can I change my query so that it only displays the first alias, and each case only ONCE, but i need it to search all the aliases.
That is, If i type in Joshi, it will still pull up that record, but the listing will display Josh, because that's the first alias.
Complicated I know.
Anybody up for the challenge if even possible?
Thanks,
Dan