tailieunhanh - Retrieve Unique Records Using Only a Select Query

Lấy Unique Records Sử dụng Chỉ có một Chọn Query tôi cần phải tìm ra khách hàng có hóa đơn. Vấn đề là khi tôi tham gia Khách hàng với các bảng đơn đặt hàng, tôi nhận được các khách hàng được liệt kê cho mỗi lệnh. | Retrieve Unique Records Using Only a Select Query I need to figure out which customers have invoices. The problem is that when I join the Customers with the Orders tables I get the customers listed for each order. I only want each customer listed once. How do I return only those customers who have orders but only once Technique For this How-To you will be using the DISTINCT clause on a SQL SELECT statement to limit the data to unique values. When you include the DISTINCT clause SQL Server uses the columns that are returned to determine how to limit the data. For the opposite affect you can include the ALL clause although it is not necessary because this is the default. You will create two SELECT statements for this task. The first one is for all records SELECT FROM Customers INNER JOIN Orders ON Customers .CustomerID To limit the records use the DISTINCT clause SELECT DISTINCT FROM Customers INNER JOIN Orders ON Steps Open and run the Visual Basic .NET-Chapter 6 solution. From the main form click on the button with the caption How-To . When the form loads you will see two option buttons Show All and Distinct with Show All selected. The SELECT statement showing an inner join between customers and order is displayed in a Label control. You will also see a DataGrid control filled with multiple entries of customers displayed see Figure . Figure . A common problem with inner joins is retrieving multiple records when you want to see just one per occurrence. If you click on the option button labeled Use Distinct then the DataGrid control will be refreshed but only one customer per set of orders will be displayed. 1. Create a Windows Form. Then place the controls listed in Table with the following properties set as displayed in Figures and . Figure . Using the DISTINCT clause gives you control over displaying unique records. Table . Control .