We will show you how to use the distinct option in order to remove the duplicate records, from a database query. We'd like to create a page, where we will display all of the cities, where our customers live. However, there could be two, or more customers from the same city, which will result in displaying the same city more than once. So, we are going to use the distinct option, for our database query, in order to display unique cities. First, let's create a new server action. Let's call it - customers (1). Then, we add a database connection step. We've already created a database connection, for this site, so we just select it, from the open connection icon (2). We've already created a database connection, for this site, so we just select it, from the open connection icon (3).
Now, right click the connection step, and add a database query (1). Add a name for your query (2). And open the query options (3). Select your database table, and add it (4). Select the column, which you like to use, and add it to the selected columns list (5). Then, enable the Distinct option. Now, we are sure, that there won't be any duplicates in the query results (6). Click the OK button, when you are done.
Save your action file, then create a server action executor, and a repeat region, which lists the records, on your page. Note: please check our previous tutorials, where we explain how to create a server action executor and repeat region, which lists the data on your page. Let's preview the results. You can see that no duplicates are displayed in the query result. That's how easy it is to use the distinct option, in order to eliminate duplicate records, from a database query.
Comments
Be the first to write a comment
You must me logged in to write a comment.