Select From db2



IBM's flagship relational database management system

Select From db2

Postby vkumarg3 » Mon Sep 24, 2012 6:25 pm

Hi all,

I am new to db2. so please help. This is my issue.

Field1 Field2

XXXXXX 'AB' OR 'CD' OR 'EF'
YYYYYY 'GH' OR 'IJ'


Is it possible to fetch field1 using field2? Like only specifying 'AB' in where clause. Not full values of tables as mentioned in table.

If so, please specify query.

Thanks in advance.
vkumarg3
 
Posts: 29
Joined: Fri Jan 06, 2012 9:29 am
Has thanked: 10 times
Been thanked: 0 time

Re: Select From db2

 

Re: Select From db2

Postby NicC » Mon Sep 24, 2012 6:31 pm

What happened when you tried a test in SPUFI?
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2690
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times

Re: Select From db2

Postby vkumarg3 » Mon Sep 24, 2012 6:42 pm

I dont know how to write query to meet that condition. So only asked you NicC.

If you give any idea , I will test in spufi.
vkumarg3
 
Posts: 29
Joined: Fri Jan 06, 2012 9:29 am
Has thanked: 10 times
Been thanked: 0 time

Re: Select From db2

Postby dick scherrer » Mon Sep 24, 2012 7:38 pm

Hello,

From what you have posted, i do not understand what you want your query to do.

Please do a more complete job showing what you "have" as input in the table(s) / rows(s) and what you want returned when the query runs correctly.

Use the Code Tag to preserve alignment and improve readability. Practice using the Preview function before Submitting.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Select From db2

Postby vkumarg3 » Mon Sep 24, 2012 7:38 pm

SELECT FIELD1
FROM TABLE-NAME
WHERE FIELD2 LIKE '%AB%' OR 'AB%'.

From my understanding I wrote this query. Whether It will work?

Help me. Thanks
vkumarg3
 
Posts: 29
Joined: Fri Jan 06, 2012 9:29 am
Has thanked: 10 times
Been thanked: 0 time

Re: Select From db2

Postby vkumarg3 » Mon Sep 24, 2012 7:39 pm

ok dick. . I used to be. But Missed somehow. Wait i will explain cleary.
vkumarg3
 
Posts: 29
Joined: Fri Jan 06, 2012 9:29 am
Has thanked: 10 times
Been thanked: 0 time

Re: Select From db2

Postby vkumarg3 » Mon Sep 24, 2012 8:03 pm

dick scherrer wrote:Hello,

From what you have posted, i do not understand what you want your query to do.

Please do a more complete job showing what you "have" as input in the table(s) / rows(s) and what you want returned when the query runs correctly.

Use the Code Tag to preserve alignment and improve readability. Practice using the Preview function before Submitting.



My Input file(test) is this:

FILD1  |FIELD2
------- ---------------------------------
XXXX   |'AB' OR 'CD' OR 'EF'
YYYY   |'GH' OR 'IJ'
ZZZZ   |'KL' OR 'AB'
-------------------------------------------

Query I written :

SELECT FILD1
  FROM TEST
 WHERE FIELD2 LIKE '%AB%' OR 'AB%'.
Code'd
Will this query give Output XXXX and ZZZZ? This is my assignment. Dont have any Mainframe IDs to test. Once I get approval only . I can proceed further.

Sorry dick Even if i have given spaces also, It s coming lik that only.
vkumarg3
 
Posts: 29
Joined: Fri Jan 06, 2012 9:29 am
Has thanked: 10 times
Been thanked: 0 time

Re: Select From db2

Postby dick scherrer » Mon Sep 24, 2012 8:47 pm

Hello,

Your data has been "Code'd". You too can do this in the "Full Editor".

At the top and bottom of the page is a link to "IBM Manuals". Look at the SQL Language reference and search for LIKE.

Why does the data in field2 contain quotes and ORs?

Is your input in "files" or database tables? It is most important to use proper terminology (i.e. sql queries are not run against files).
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: Select From db2

Postby NicC » Mon Sep 24, 2012 8:52 pm

Unless you have AB embedded in your data you can use
WHERE FIELD2 = 'AB'

To use the code tags use the full editor (click on POST REPLY not Quick Reply, higlight the text to be 'coded' and click on the Code button. Then use the Preview button instead of the Submit button. If it looks OK now click on the Submit button otherwise scroll, as necessary, to the input panel and continue editing/previewing.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2690
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post