Inner join query
Please go thourgh A开发者_C百科ttached Image where i descirbed my scenario:
I want SQL Join query.
Have a look at something like
SELECT *
FROM Orders o
WHERE EXISTS (
SELECT 1
FROM OrderBooks ob INNER JOIN
Books b ON ob.BookID = b.BookID
WHERE o.OrderID = ob.OrderID
AND b.IsBook = @IsBook
)
The query will return all orders based on the given criteria.
So, what it does is, when @IsBook = 1
it will return all Orders where there exists 1 or more entries linked to this order that are Books. And if @IsBook = 0
it will return all Orders where there exists 1 or more entries linked to this order that are not Books.
Inner join is a method that is used to combine two or more tables together on base of common field from both tables. the both keys must be of same type and of length in regardless of name.
here is an example, Table1 id Name Sex 1 Akash Male 2 Kedar Male
similarly another table Table2 id Address Number 1 Nadipur 18281794 2 Pokhara 54689712
Now we can perform inner join operation using the following Sql statements
select A.id, A.Name, B.Address, B.Number from Table1 A INNER JOIN Table2 B ON A.id = B.id
Now the above query gives one to one relation details.
精彩评论