Sorry if i'm made a mistake in my thread's title.
I want to ask query about joining 5 tables and showing only 2 row in my asp.net gridview list
I have created 3 tables
A: CustId, CodeA, FullNameA, SurNameA
B: CustId, CodeB, FullNameB, SurNameB
C: CustId, CodeC, FullNameC, SurNameC
All of that tables will be joined with [Customer], and [Code] tables to show 'CustomerName' from [Customer] and 'CodeName' from [Code]
There are the data in [A],[B],[C], [Customer], And [Code] Tables:
A
-------------------------------------------------------------
CustId | CodeA | FullNameA | SurNameA
71 A001 Test1A Sur1A
71 A002 Test2A Sur2A
B
-------------------------------------
CustId | CodeB | FullNameB | SurNameB
71 B001 Test1B Sur1B
71 B002 Test2B Sur2B
C
-------------------------------------------
CustId | CodeC | FullNameC | SurNameC
71 C001 Test1C Sur1C
71 C002 Test2C Sur2C
Customer
=============================================
CustId | CustomerName | Gender |
71 Agripa Male
Code
=============================================
CodeID | CodeName | CodeName2 |
A001 Amoxiclyin Amoxyclin
B001 Brulamin Brulamin
C001 AXMetan AXMetan
A002 Aloximin Aloximin
etc until C002...
There is my query:
SELECT
cst.CustomerName, cd1.CodeName, cd2.CodeName, cd3.CodeName
, a.*, b.*, c.*
FROM [A] a
INNER JOIN [Customer] cst ON a.CustId = cst.CustId
INNER JOIN [B] b ON b.CustId = cst.CustId
INNER JOIN [C] c ON c.CustId = cst.CustId
INNER JOIN [Code] cd1 ON cd1.CodeID = a.CodeA
INNER JOIN [Code] cd2 ON cd2.CodeID = b.CodeB
INNER JOIN [Code] cd3 ON cd3.CodeID = c.CodeC
I want to show it to list only 2 row based on A,B,C Table that only have 2 row , for example:
CustomerName | CodeNameA | FullnameA | SurNameA | CodeNameB | FullNameB | .....
Agripa Amoxiclyn Test1A Sur1A Test1B Sur1B .....
Agripa Aloximin Test2A Sur2A Test2B Sur2B .....
But, it show:
CustomerName | CodeNameA | FullnameA | SurNameA | CodeNameB | FullNameB | .....
Agripa Amoxiclyn Test1A Sur1A Test1B Sur1B .....
Agripa Aloximin Test2A Sur2A Test2B Sur2B .....
Agripa Aloximin Test1A Sur1A Test1B Sur1B .....
Agripa Amoxiclyn Test1B Sur2A Test2B Sur2B .....
Agripa Aloximin Test1B Sur1B Test2B Sur1B .....
...until 8 row (and its mixed up with the data) -> it should be only 2
since I only have 2 data input in A,B,C tables
Please help me to know what should i do with the query to show only 2 row based on 2 row input in A,B,C tables and not mixed up and create another necessary row. Thanks.