Click here to Skip to main content
14,298,696 members
Rate this:
Please Sign up or sign in to vote.
See more:
From two Tables i have did the following Query "Look at what I have tried"

1- my Problem that i'm getting a very huge number back in rows which is '70805' in 00:00:01 time and in fact it must be in rows only '713' in 00:00:00 time .

2- the Query is between two tables [dbo].[FXXL$Purchase Header] und [dbo].[FXXL$Purchase Line] and should get the columns : Description, Size, Colour, Quantity, NO_, Brand and

OrderDate between 1.6.2018 und 31.12.2018
Brand must be = 'CUBE'
Ship-to Name 2 must be = 'Zentrallager'

and the Result must be sorted to Size, and Colur

3- How can I find the different types of Brand = 'CUBE' if it has different colours and sizes ?

What I have tried:

select pl.Brand,pl.Description,pl.Size,pl.Colour,pl.Quantity, pl.No_ , ph.[Ship-to Name], ph.[Ship-to Name 2], ph.[Order Date] 
from [FXXL$Purchase Header]ph ,[FXXL$Purchase Line]pl

where ph.[Order Date] between'01.06.2018' and '31.12.2018' and ph.[Ship-to Name 2] ='Zentrallager' and pl.Brand = 'CUBE'
order by pl.Size, pl.Colour 
Updated 3-Sep-19 5:24am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

The problem is that you are using SELECT to return rows from two tables: and that means that SQL tries it's best to return a separate row for each combination.
For example, if you have two rows in TableA and three rows in TableB then a simple query:
SELECT A.ID, A.[Desc], B.ID, B.[User]
FROM TableA A, TableB B
Will give you six rows:
ID      Desc     ID      User
1       D1       1       U1        
1       D1       2       U2        
1       D1       3       U3        
2       D2       1       U1        
2       D2       2       U2        
2       D2       3       U3
Two for each row in TableA and three for each row in TableB
If you want to return just the rows in TabelA with some informationation from related rows in TableB, then you need to use a JOIN on the appropriate columns:
SELECT A.ID, A.[Desc], B.[User]
JOIN TableB ON a.ID = b.TableAID
Since we don't have access to your data, and have no idea what the relationship(s) might be, you will have to work out the exact JOIN format for yourself!
Abdalla Ben Omran 3-Sep-19 11:51am
The King of SQL Server 'Paul' . Thank you once again . I have found the relationship between the two tables .
i will be happy if you could explain to me the point Nr 3 .
OriginalGriff 3-Sep-19 12:10pm
I assume you mean JOINs?
If so:
is a good place to start (they are pretty powerful, so you have some reading ahead!)
Abdalla Ben Omran 4-Sep-19 3:49am
great . thanks
OriginalGriff 4-Sep-19 3:52am
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100