Kindly review this simple SQLite-fiddle .
If any word in the column ITEM of table TWO matches any word in the column NAME_2 of table ONE, there should be a result(s).
Tried many permutes, yet not sure how to form the query for achieving this. Should the GLOBclause be used instead of LIKE, or perhaps some other wildcard patterns?
Many thanks in advance!
As per my comment, I think you can make use of instr as well. For example:
SELECT * FROM Table1 T1, Table2 T2 where instr(T2.NAME_2,T1.ITEM);
The above should return rows where T2.NAME contains a string = T1.ITEM
Related
If I have too many columns and a bunch of them start with similar strings , is there a way in Kusto to select them based on this pattern , such as using wild cards etc ?
e.g. Assuming we have some of the columns like datafield1, datafield2 ... , something like the following would be helpful
mytable | project datafield*
I know that this is not syntactically valid , so is there any workaround for achieving this easily?
project-keep does exactly what you want:
mytable | project-keep datafield*
I want to match a number from two different table and if it's found in any table it will display that..
INPUT FROM VALUE("/mydirectory/test.csv").
REPEAT:
IMPORT c.
FOR EACH table1 NO-LOCK WHERE table1.ordernumber=c.
IF AVAILABLE table1 THEN
DISPLAY table1.ordernumber table1.orderdate.
ELSE IF NOT AVAILABLE table1 THEN
FIND FIRST table2 NO-LOCK WHERE table2.ordernumber=c.
IF AVAILABLE table2 THEN
DISPLAY table2.ordernumber table2.orderdate.
END.
END.
So far I have written this much but it's not giving correct results. Appreciate help on this regards. Thanks.
Using IF AVAILABLE table1 within the FOR EACH makes no sense, as the FOR EACH only iterates matching records in table1.
Try this:
INPUT FROM VALUE("/mydirectory/test.csv").
REPEAT:
IMPORT c.
FIND table1 WHERE table1.ordernumber=c NO-LOCK NO-ERROR.
IF AVAILABLE table1 THEN
DISPLAY table1.ordernumber table1.orderdate.
ELSE DO:
/*IF NOT AVAILABLE table1 THEN*/
FIND FIRST table2 WHERE table2.ordernumber=c NO-LOCK NO-ERROR.
IF AVAILABLE table2 THEN
DISPLAY table2.ordernumber table2.orderdate.
END.
END.
Without knowing your tables/indexes I can only guess if you need to do unique finds (current code) or add the FIRST option to your FIND statements.
If you want the display of table2.ordernumber and table2.orderdate in place of the fields from table1, you can change the second DISPLAY statement like this - using the place holder syntax:
DISPLAY table2.ordernumber # table1.ordernumber
table2.orderdate # table2.orderdate.
I'm using SQLite to deal with tons of data (like 100gb of data).
I need to seach the value of one column in other table in the fastest way possible.
For example, I need to find the following values of Table 1
[COD]
C62
K801
And then find them in Table 2:
[COD_2]
C60-C63
K80-K81
My desired result is something like:
[COD_1] [COD_2]
C62 C60-C63
K801 K80-K81
Since I have a lot of data, it is inefficient to do something like:
SELECT *
FROM TABLE_1, TABLE_2
WHERE COD_1 LIKE '%' || COD_2 || '%';
Instead, I was trying to do this:
SELECT *
FROM TABLE_1
WHERE COD_1 IN (SELECT COD_2 FROM TABLE_2);
Of course that this doesn't result because the codes are not exactly the sames. Is there a way to search for similar values of one column (something like the LIKE operator) in other table by using IN? Or other way that doesn't cross TABLE_1 and TABLE_2?
Thank you!!!
useful to me.
Based on the small data set shown, and my presumed answer to #Shawn's question (K801 is a typo and is meant to be K80 or K81) I assume the following problem description:
Find a row in COD_2 such that the value in COD_1 is between {value1}-{value2} in COD_2; the - being significant and dependable.
I cannot speak to speed, but I would approach it this way:
SELECT value1, value2
from COD_1,COD_2
where value1 between substr(value2,1,instr(value2,'-')-1) and substr(value2,instr(value2,'-')+1)
The thought being: split the value from COD-2 into a "start" and an "end" value.
I use SQLITE3 for my DB,i have 3 table: Doc table (id,name,date),tag table (id,name,count) and the relation table (id_doc, id_tag) that connect doc and tag table (many to many relation). Now i'm stuck on a query: i want to select the id of document related to tag 1,2 and 3 but i can't figure out how to do this.
anyone can help me?
If I understand correctly, you can use aggregation and having. Something like this:
select id_doc
from relation r
where id_tag in (1, 2, 3)
group by id_doc
having count(*) = 3;
I have a table which has a column named "directory" which contains strings like:
c:\mydir1\mysubdir1\
c:\mydir2
j:\myotherdir
...
I would like to do something like
SELECT FROM mytable WHERE directory is contained within 'c:\mydir2\something\'
This query should give me as a result:
c:\mydir2
Ok, I've just found that sqlite has a function instr that seems to work for my purpose.
Not sure about the performance, though.