0

I want to display all information of table program but it must based on other table (which is Line), I try to use join but it will show ALL information from ALL TABLE.

Can someone help me to create the query or just tell me what should i do.

TABLE LINE 
------------
LineName

TABLE PACKAGE
-------------
PackageNo
PackageName
Line

TABLE FAMILY
------------
FamilyCode 
FamilyName
TestQuant

TABLE PROGRAM
-------------
FamilyName
TestType
FolderPath
TestProgram
Remark
CreateTime

And this is what i have done

SELECT * FROM Program AS D
JOIN Family AS Q ON D.FamilyName = Q.FamilyName
JOIN Process AS V ON Q.TestQuant = V.PackageNo
JOIN Line AS R ON R.LineName = V.Line
WHERE V.Line = 'LINE1'

WHAT I HAVE CHANGE

SELECT DISTINCT D.FamilyName, D.TestType, D.FolderPath, D.TestProgram, D.Remark, 
D.CreateTime
FROM Program D
INNER JOIN Family Q ON D.FamilyName = Q.FamilyName
INNER JOIN Process V ON Q.TestQuant = V.PackageNo
INNER JOIN Line R ON R.LineName = V.Line
WHERE V.Line = 'LINE1'
Far
  • 27
  • 9

2 Answers2

0

If you need ONLY the data from Program table, try this:

SELECT D.FamilyName, D.TestType, D.FolderPath, D.TestProgram, D.Remark, D.CreateTime
FROM Program D
JOIN Family Q ON D.FamilyName = Q.FamilyName
JOIN Process V ON Q.TestQuant = V.PackageNo
JOIN Line R ON R.LineName = V.Line
WHERE V.Line = 'LINE1'
peev
  • 302
  • 3
  • 13
0

It sounds like you may need a left or right outer join. Here is an example question that has some very good explanations of JOINs in the answers, the venn diagrams really helped me understand:

SQL JOIN and different types of JOINs

An example of how you might construct a join (taken from Techonthenet)

SELECT columns
FROM table1
RIGHT [OUTER] JOIN table2
ON table1.column = table2.column;

Hope this helps, SQL JOIN can be a bit tricky to understand.

Groggo
  • 111
  • 3
  • i change it to inner join which i refer to this https://stackoverflow.com/a/38578/7984694 , but thanks for the info :D – Far Jun 09 '17 at 08:18
  • @Far No problem at all, I'd like to wish you the best of luck. The more questions you ask the better! – Groggo Jun 09 '17 at 09:04