Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Help with sql query (select from a table using patter matching(%) )
Need help to write a query to achive the following.
Have 3 tables - Main_Table , Include_Table & Exclude_Table There is one ID column in the main_table.
Need to select the rows from the main table where
ID like Include_Table.START ||'%' || Include_Table.END
BUT ID NOT LIKE Exclude_Table.START ||'%' || Exclude_Table.END
One way to achive this is:
select Name, ID from Main_Table MT, Include_Table IT
Where MT.ID LIKE IT.START ||'%' || IT.END
MINUS
select Name, ID from Main_Table MT, Exclude_Table ET
Where MT.ID LIKE ET.START ||'%' || ET.END
Is there any other better way of acheiving the required as I want to avoid the above mentioned
query as my actual table is huge in size.
An example to present a more clear picture:
Main_Table
NAME | ID X | CRRL Y | CKYL Z | CRZL A | URRP B | UZRP C | UJRP P | ZWWK Q | ZPPK D | ZGTH
Include_Table
START | END C | L U | P Z | K
Exclude_Table
START | END CR | L CJ | L UR | P UJ | P ZP | K
The output should be
NAME | ID Y | CKYL B | UZRP P | ZWWK
Thanks Received on Mon Dec 19 2005 - 12:19:36 CST
![]() |
![]() |