passing a variable to SQL statement in KNIME - mysql

Using KNIME, I would like to analyze data in a specific subset of columns in my database
but without using limiting SQL queries such as
Select *
From table
Where name like 'PAIN%'
Is there a way to do this in KNIME?

Try to find specific value within the column of choice by using:
Select distinct(column_name) from table;
You can pick from the expected result to filter your data
Select * from table column_name like 'result_one';
Assuming the column_name data type is in character.

To filer columns use the "Column Filter" node. You can filter the columns specifically, by RegEx on the column name or by column type (int, double, etc.) To filter rows based on content, use the "Row Filter" node, and select column to test and "filter based on collection elements" using pattern matching. This can also use RegEx. For mulitple columns use multiple nodes.

the knime did not support like for now, so I used the mysql locate or FIND_IN_SET function
SELECT id FROM address where LOCATE($street_Arr[0]$,street) > 0
SELECT id FROM address where FIND_IN_SET($street_Arr[0]$,street) > 0
however in the same situation u might be able to use knime joins much faster.

Related

Select rows in SQL partially matching an input input

I would like to select rows in my table (I'm using Google Sheet for that purpose) which content is included in the string.
For example, rows included in table called Jobportal, column Test:
How to find work
Work permit
Jobs
Temporary jobs
I want to select all the rows that contain any word of my input, so if I write "i'm looking for a job", I need to select rows Jobs and Temporary jobs. If I write "where is my work?", I need to select How to find work and Work permit.
I've tried this query, but it's returning wrong/unexpected results.
select * from Jobportal where 'im looking for a job' LIKE CONCAT('%',Test,'%');
You can use regular expressions. Assuming that what the user types does not have special characters:
where test regexp replace('im looking for a job', ' ', '|')
That said, for performance you might want to consider using full text search capabilities.

MySQL search for keywords containing apostrophe or not

I have a MySQL database containing a list of UK towns and one of which is "Connah's Quay".
I want to be able to return results for "Connah's Quay" whether I have used the apostrophe or not, so "Connah's Quay" and "Connahs Quay" returns "Connah's Quay".
Rather than creating a field containing both versions (one with and another without the apostrophe), is there a SQL query I can run that will return results whether I have used the apostrophe or not?
QUERY:
SELECT * FROM uk_postcodes WHERE postal_town LIKE "connahs%";
Standard approach would be to normalise the data and search on that, so something like:
SELECT * FROM uk_postcodes WHERE REPLACE(postal_town, '''', '') LIKE 'connahs%';
This is a bit horrible to do on the fly (and not index friendly), so you would be better to store on table (also means you can also then cope with "Stow-cum-Quy" vs. "Stow cum Quy", etc.)
You might try this:
SELECT *
FROM uk_postcodes
WHERE REPLACE(postal_town,"'","") LIKE CONCAT(REPLACE("connah's","'",""),"%");
This removes the apostrophes from both the search term and the column value before the comparison.

Show Fields but with content

i'm trying to show fields names on a combobox, but I need only those that are not null or have blank spaces.
I all ready have the field names with this query:
SHOW FIELDS FROM model WHERE type LIKE 'varchar(15)'
Any idea about how can i do this?
Update:
I'm working with an old database who is poorly designed. I attached an image:Database Screenshot This is a tire sizes database, so i need to get the years by model who has the size captured to show them in a combo box.
You can use your current query to get the "candidate" fields, but (short of some very complicated dynamic sql) you'll need to build a separate query to determine which candidates are pertinent. Generically, something like:
SELECT SUM(IF(field1 REGEXP '[a-zA-Z0-9.]+', 1, 0) > 0 AS showField1
, SUM(IF(field2 REGEXP '[a-zA-Z0-9.]+', 1, 0) > 0 AS showField2
, ...
FROM theTable
;
Depending on what you consider "has values" the regexp string may need adjusted; learn more here: http://dev.mysql.com/doc/refman/5.7/en/regexp.html
If the table is huge (large number of rows), you may be better off querying on each field separately like this (the one above will be looking at the whole table without some sort of WHERE to reduce the rows examined):
SELECT 1 FROM theTable WHERE fieldX REGEXP '[a-zA-Z0-9.]+' LIMIT 1;
Treating having a query result as "yes" and no result as "no content".

MySql extract data from a database based on two columns

I Am trying to create/run an my sql query in such a way that the sql selects data based a some conditions from Column 1 (USER) but at the same time Excludes some data, based on some conditions from column 2 (ADDRESS)
E.g.:
SELECT ADDRESS,USER
FROM Data1.Table1
WHERE FIELD(USER,'%AMIT%','%JOHN%','%SANDEEP%','%WARNE%')
AND ORIGINATING_ADDRESS NOT LIKE 'MUMBAI','CHINA','PAKISTAN'
This is giving error.Can some one please help ?
Use NOT IN to discard list of values from select. Considering that you want to discard when there is exact match
ORIGINATING_ADDRESS NOT IN ('MUMBAI','CHINA','PAKISTAN')
When you want to use pattern search and discard the use this
ORIGINATING_ADDRESS NOT LIKE '%MUMBAI%' OR
ORIGINATING_ADDRESS NOT LIKE '%CHINA%' OR
ORIGINATING_ADDRESS NOT LIKE '%PAKISTAN%'
For a set of values, use NOT IN, instead of NOT LIKE.
You might find regular expressions simpler for this purpose:
SELECT ADDRESS,USER
FROM Data1.Table1
WHERE USER REGEXP 'AMIT|JOHN|SANDEEP|WARNE' AND
ORIGINATING_ADDRESS NOT REGEXP 'MUMBAI|CHINA|PAKISTAN';

Regex not supported in sql command with "contains" clause

I am not a seasonal Windows user, I got a task wherein I had to query the Window Index search table i.e "Systemindex" for fetching some user specific data from the db.
And for this I have to match a pattern basically a regular expression while fetching the data.
SELECT System.FileName, System.ItemPathDisplay, System.DateCreated, System.DateModified, System.ItemName, System.KindText FROM Systemindex WHERE Contains('“(?=^[A-Za-z\d!##\$%\^&\*\(\)_\+=]{9,32}$)”');
The above would allow us to search for say stored passwords.
But when I query the db using the below command I was getting an error. And later I came to know that the "contains" clause
does not support regular expression. Is there an alternative to achieve this?
there is REGEXP operator http://dev.mysql.com/doc/refman/5.7/en/regexp.html,
use smth like this
SELECT * FROM Systemindex WHERE some_column REGEXP 'your_regex'