Jump to content

SQL doubt


bevarse

Recommended Posts

hello sql gurus,

naaku oka simple select statement ki help kaavali, 

2 tables ni join cheyyali. Example ki order table and order status table anukundam. 

I need to join on orderId but should only select the orders that are not delivered. So nenu ee kinda 2 tables join chesi query chesthe I should see only orderId 2 and 3 in the query result.

any ideas on the best way to do this?

 
OrderId ItemID OrderDate
1 11650 8/8/2017
2 11660 8/8/2017
3 11670 8/8/2017

 

StatusId OrderId  Status
1 Placed
2 Received
3 Shipped
4 Delivered
5 Placed
6 Received
7 Shipped
8 Placed
9 Received
Link to comment
Share on other sites

Just now, BostonBullodu said:

Select O.ItemId, O.OrderDate,S.Status

FROM dbo.Orders O 

JOIN dbo.Status S  ON O.orderid = S.orderid

where S.Status != 'Delivered'

Ila cHesthe I will still get order ID 1 in the result kada bro.

Link to comment
Share on other sites

2 minutes ago, bevarse said:

Ila cHesthe I will still get order ID 1 in the result kada bro.

requirement enti bro

not delivered ante migathavi ravali kada 

Link to comment
Share on other sites

Just now, BostonBullodu said:

requirement enti bro

not delivered ante migathavi ravali kada 

requirement yenti ante, I want to show the orders that are not yet delivered. 

so only order id 2 and 3 kanapadali query result lo and order 1 is already delivered kaabatti it should not be displayed

Link to comment
Share on other sites

Select O.orderID ,O.ItemId, O.OrderDate,S.Status

FROM dbo.Orderr O 

JOIN dbo.Status S  ON O.orderid = S.orderid

where O.orderID not in ( select OrderId from  Status where Status = 'Delivered')
 

Link to comment
Share on other sites

5 minutes ago, khabardar said:

Select O.ItemId, O.OrderDate,S.Status

FROM dbo.Orders O 

JOIN dbo.Status S  ON O.orderid = S.orderid

where orderID in ( select OrderId from  Status where S.Status <> 'Delivered')

Status table lo orderid 1 ki other entried vunnai kada bro so this also returns orderid 1 in the result set. 

Link to comment
Share on other sites

4 minutes ago, Suhaas said:

SELECT O.OrderId
FROM orders O
WHERE NOT EXISTS (SELECT S.OrderId FROM status S WHERE O.OrderId = S.OrderId and S.status = 'delivered')

Suhas bhayya you rock again. 

neeku stackoverflow lo account vunda, I will post this and also the jquery help you did and you can answer it there

Link to comment
Share on other sites

Just now, bevarse said:

Suhas bhayya you rock again. 

neeku stackoverflow lo account vunda, I will post this and also the jquery help you did and you can answer it there

No worries Bro. Happy to help. 

StackOverflow la undi kani lite bro. Take it easy

Link to comment
Share on other sites

Select O.orderID ,O.ItemId, O.OrderDate,S.Status

FROM dbo.Orderr O 

JOIN dbo.Status S  ON O.orderid = S.orderid

where O.orderID not in ( select OrderId from  Status where Status = 'Delivered')
 

-- I tested bro.. edi pakka pani chestadi.. chudu.. 100% sure

Link to comment
Share on other sites

Just now, bevarse said:

@Suhaas asalu nee daily work activity yenti bhayya how come you are so smart ? yemi tintav yela practice chestav ?

@khabardar and @BostonBullodu not to offend you, you were the first ones to offer help. 

 

daily work activity yenti - AFDB @3$%

how come you are so smart ? - Naak antha scene ledu bro. 

Link to comment
Share on other sites

4 minutes ago, bevarse said:

@Suhaas asalu nee daily work activity yenti bhayya how come you are so smart ? yemi tintav yela practice chestav ?

@khabardar and @BostonBullodu not to offend you, you were the first ones to offer help. 

 

braboyii eh chinna query ke antha happy ayyava way to go brother now you will understand diff between in and not exists especially if there are nulls check it out.... 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...