Home » SQL & PL/SQL » SQL & PL/SQL » Unable to fisue out simple sql
Unable to fisue out simple sql [message #598535] Tue, 15 October 2013 12:16 Go to next message
DIPRINKS
Messages: 57
Registered: July 2013
Location: Michigan
Member
Unable to figure out why this query results 0 records although there are records in the one table which doesnt exist in another table.
SELECT count(*)
FROM   advance.primary_gift t
WHERE  t.prim_gift_receipt_number NOT IN
       (SELECT receipt_number
        FROM   advance.gift_tender_type)---0 records
        
        


SELECT *
FROM   advance.primary_gift t where prim_gift_receipt_number in (0001088058,0001046163,0001046164,0001046170,0001046171)---5 records
SELECT *
FROM   advance.gift_tender_type t where receipt_number=0001088058 in ('0001088058','0001046163','0001046164','0001046170','0001046171')---0 records
icon2.gif  Re: Unable to fisue out simple sql [message #598536 is a reply to message #598535] Tue, 15 October 2013 12:22 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Read this post and the following ones.

icon13.gif  Re: Unable to fisue out simple sql [message #598538 is a reply to message #598535] Tue, 15 October 2013 12:24 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Also a STRING is different from a NUMBER.
A NUMBER has no leading 0.

Re: Unable to fisue out simple sql [message #598546 is a reply to message #598538] Tue, 15 October 2013 13:17 Go to previous messageGo to next message
DIPRINKS
Messages: 57
Registered: July 2013
Location: Michigan
Member
but both the fields are varchar datatype.the only difference is one is nullable and other is not.
icon13.gif  Re: Unable to fisue out simple sql [message #598552 is a reply to message #598546] Tue, 15 October 2013 13:33 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
the only difference is one is nullable and other is not.


But not the queries you show us:
0001088058,0001046163,0001046164,0001046170,0001046171
and
'0001088058','0001046163','0001046164','0001046170','0001046171'
One is numbers the other one is strings
When you convert number 0001088058 to string you have '1088058' not '0001088058'.

In the end, put a test case so we can reproduce what you have.

[Updated on: Tue, 15 October 2013 13:33]

Report message to a moderator

Re: Unable to fisue out simple sql [message #598588 is a reply to message #598552] Tue, 15 October 2013 16:36 Go to previous message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
this isn't valid sql:
SELECT *
FROM   advance.gift_tender_type t where receipt_number=0001088058 in ('0001088058','0001046163','0001046164','0001046170','0001046171')
Previous Topic: Connect by to Get Parent and Supervisor Details in Oracle
Next Topic: PL/SQL
Goto Forum:
  


Current Time: Fri Apr 26 07:24:12 CDT 2024