This topic is locked

Select distinct data while allowing search by other columns

9/9/2025 7:33:13 PM
PHPRunner Tips and Tricks
Sergey Kornilov admin

We have a table with the car owners data. Some people may have nore than one car. Our task is to provide a UI that will allows to search by fields like car color or year of make but display a list of matching the search without duplicates.

img alt

For instance we want to display a list car owners with red cars. The correct query would be as follows:
select distinct name from table where property2='red'

The problem is that fields like property1, property2 etc need to be a part of the select query, otherwise we cannot select those fields to be searchable. Luckily, there is an easy way to implement this in PHPRunner.

  1. Leave the default SQL query intact:

SELECT
name,
property1,
property2,
property3,
property4
FROM
table
  1. Make fields like property1, property2 etc searchable but remove them from the List page.


  2. In BeforeSQLQuery event use the following code:



$strSQL = "select distinct `name` from `table`";
if($strWhereClause)
$strSQL = "select distinct `name` from `table` where ".$strWhereClause;

This is it. Happy coding!