How to retrieve blank records using talend integration - integration

I want to retrieve blank records from excel file.
Records are:
+----+------+
| id | name |
+----+------+
| 1 | a |
+----+------+
| 2 | b |
+----+------+
| 3 | |
+----+------+
| 4 | d |
+----+------+
| | e |
+----+------+
| 6 | f |
+----+------+
Here I want to retrieve 3rd and 5th record.
Can anyone please give me an idea.

I guess that your blank records dont contain space " " .Try to use tFilterRow and this conditions :
input_row.id == null || input_row.name == null
In case that columns are nullable. Otherwise:
input_row.id.equals("") || input_row.name.equals("")

i have tried this
using t filter row tried to find blank records.

Related

MySQL Order by id, unless the record has a parent_id

I'm using Laravel (and MySQL of course) to build a pages module, a page can have 1 parent
This is my current data, and using order_by="id" it's also returned like this.
+----+-----------+
| id | parent_id |
+----+-----------+
| 1 | NULL |
| 2 | NULL |
| 3 | 1 |
| 4 | 1 |
+----+-----------+
Now I'm wondering if it's possible to have a result set where the children are ordered underneath their parent. Which would render the following result
+----+-----------+
| id | parent_id |
+----+-----------+
| 1 | NULL |
| 3 | 1 |
| 4 | 1 |
| 2 | NULL |
+----+-----------+
Thoughts
Maybe it is possible to generate an order_by query that orders by id, but assigns a temporary id in a temp column, in between the others, in case the row has a parent_id?
So ideally the 2 children (3, 4) of the parent (1) are shown just below it.
You can use coalescefunction:
ORDER BY coalesce(`parent_id`,`id`),`parent_id` is not null
P.S. ,parent_id is not null is needed for the case even (2,1) inserted instead of (2,null) in the order of VALUES(2,1),(1,null),(3,1),(4,1)(special thanks to #splash58)
Demo

Update MS Access table empty fields based on same table

In MS Access database, I'm working with a table that has rows. In some cases not all columns of the rows are filled. I want to create an update query to update the values of the empty fields with data from other rows where the column is not empty.
googled the question but no satisfying answer has been found. Can someone show me how the query should be build?
Current table looks like
| Invoicenumber | Customer | Date |
|---------------|----------|---------|
| 5 | 12 | 12-6-19 |
| 5 | | 12-6-19 |
| 5 | | 12-6-19 |
| 5 | | 12-6-19 |
| 6 | 18 | 15-6-19 |
| 6 | | 15-6-19 |
| 6 | | 15-6-19 |
| 7 | 20 | 20-6-19 |
| 7 | | 20-6-19 |
I need the table to look like this after updating:
| Invoicenumber | Customer | Date |
|---------------|----------|---------|
| 5 | 12 | 12-6-19 |
| 5 | 12 | 12-6-19 |
| 5 | 12 | 12-6-19 |
| 5 | 12 | 12-6-19 |
| 6 | 18 | 15-6-19 |
| 6 | 18 | 15-6-19 |
| 6 | 18 | 15-6-19 |
| 7 | 20 | 20-6-19 |
| 7 | 20 | 20-6-19 |
You can do it with just SQL by joining the table to itself:
UPDATE
Invoices
INNER JOIN Invoices AS Inv2
ON Invoices.InvoiceNumber = Inv2.InvoiceNumber
SET
Invoices.Customer = Inv2.Customer
WHERE
(Invoices.[Customer] Is Null)
AND (Inv2.Customer IS NOT NULL)
You can place a Switch statement into the update to choose the value to update based on the state of the CUSTOMER field.
Update TestTable
Set CUSTOMER = Switch(CUSTOMER is Null,OTHER_FIELD,CUSTOMER = '',OTHER_FIELD,CUSTOMER<>'',CUSTOMER)
This statement will update the CUSTOMER field to the OTHER_FIELD where CUSTOMER is blank or CUSTOMER is Null. If CUSTOMER has a value, it sets it to that value (essentially leaving it as the same.)
The 'SWITCH' statement is Access's version of a 'Switch' or 'Select Case' in code, where the first parameter is the condition to check, the parameter after it is the value to take if the previous condition returns true. So...
Switch(1=1,'YES',2=1,'NO', case 3, return 3, case 4, return 4, etc., etc.,)
would return the 'YES' because 1 is equal to 1.
There would be a more eloquent way to do this with code, but in an Access query, I don't know any other way.
Try using domain aggregate function to pull the Customer:
UPDATE table1 SET table1.Customer = DMax("Customer","table1","Invoicenumber=" & [Invoicenumber])
WHERE (((table1.Customer) Is Null));
Question answered by solution mentioned by #John Mo. Used his code to update table with data available within the table.

MySQL How can I make a better query to connect two tables through my bridge table?

I have these tables:
words:
+----+------+
| ID | DATA |
+----+------+
| 1 | jo |
| 2 | yes |
| 3 | jupp |
| 4 | yeah |
| 5 | jepp |
| 6 | joah |
| 7 | ne |
| 8 | nee |
| 9 | no |
| 10 | nope |
| 11 | nah |
+----+------+
statements:
+----+------+
| ID | DATA |
+----+------+
| 1 | ja |
| 2 | nein |
+----+------+
and a bridge table that connects the words from table "words" with the DATA from table "statements":
bridge:
+--------------+---------+
| ID_statement | ID_word |
+--------------+---------+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 1 | 4 |
| 1 | 6 |
| 2 | 8 |
| 2 | 9 |
+--------------+---------+
I wanted to get a SELECT QUERY to get all words associated with the statement "ja".
this query does the job, but seems more complicated than it should be:
SELECT words.DATA FROM words
JOIN bridge ON words.ID = bridge.ID_word
JOIN statements ON statements.ID = bridge.ID_statement
WHERE statements.ID = (
SELECT ID FROM statements WHERE statements.DATA = "ja"
);
Intuition tells me that I am doing that far to comlicated, but I can't figure out where the complication lies.
awkward.
I like to name the primary keys the same as the columns that reference them. So in your example, in the words table, you'd name the primary key ID_word. In the statements table, you'd name the primary key ID_statement.
The advantage is that you can make your SQL join a little more concise with the USING(...) syntax. This syntax assumes there's a column by that name in both tables of a join, and you want the join to match where the column is equal to the same column in the other table.
SELECT words.DATA FROM words
JOIN bridge USING (ID_word)
JOIN statements USING (ID_statement)
WHERE statements.DATA = 'ja';
Also you don't need to run a subquery in your example. The rows in statement matching the IDs from the rows in statement where DATA='ja' are the same set as the rows in statement where DATA='ja'.
how would one describe the relationship here? one-to-many?
The relationship modeled by a bridge table is a many-to-many relationship. The specific data in your example doesn't show it, but it's possible that many different statements could reference the same word. What you do show is that each statement can reference many words.

Delete duplicate records in MySql in one single query

I have this MySQL table:
+------+------+
| id | name |
+------+------+
| 1 | John |
| 1 | John |
| 2 | Jill |
| 2 | Jill |
| 3 | Jack |
| 3 | Jack |
+------+------+
Can anyone please tell me how to delete the duplicate records and keep one record from this table in MySQL in one single query (i.e without creating another table)?
You have basically two options unless you want to do something more precise:
select * from table group by ID
or, alternatively:
select distinct(ID), name from table

mysql select with group by returning rows with a preference order

I have the following mysql query result:
+----+------------+-------------+
| id | title | lang |
+----+------------+--------------
| 1 | ola1 | 1 |
| 1 | hello1 | 2 |
| 1 | bonjour1 | 3 |
| 2 | ola2 | 1 |
| 2 | bonjour2 | 3 |
| 3 | hello3 | 2 |
| 4 | bonjour4 | 3 |
+----+------------+-------------+
What I want is a group_by query by id and that gives me for each id the title with a order of preference for lang field. Example:
Result for lang preference order 1, 2, 3:
+----+------------+-------------+
| id | title | lang |
+----+------------+--------------
| 1 | ola1 | 1 |
| 2 | ola2 | 1 |
| 3 | hello3 | 2 |
| 4 | bonjour4 | 3 |
+----+------------+-------------+
Result for lang preference order 3, 2, 1:
+----+------------+-------------+
| id | title | lang |
+----+------------+--------------
| 1 | bonjour1 | 3 |
| 2 | bonjour2 | 3 |
| 3 | hello3 | 2 |
| 4 | bonjour4 | 3 |
+----+------------+-------------+
Thanks!
It is either not possible, or, not with in my SQL skills to execute that in one query. I always end up using a temporary template and two SQL commands for these problems:
(assuming that your table is called Table1 and the temporary table should be called tempTable)
SELECT Table1.id, Min(Table1.lang) AS Min_Of_lang INTO tempTable FROM Table1 GROUP BY Table1.id ORDER BY Table1.id;
SELECT Table1.* FROM tempTable INNER JOIN Table1 ON (tempTable.MinOflang = Table1.lang) AND (tempTable.id = Table1.id);
The first command creates a new table (that overrides the current table if it exists). The second command uses the first table to produce the desired result set.
To change from your first desired results table to the second, use Max instead of min in the first query.
Somebody else may well have a more elegant solution than mine. Also, an extra SQL statement could be added to delete the temporary table.
This is a feature that is not defined in MySQL. The displayed value in a non-aggregated column is undetermined. read more here (MySQL Documentation).
(Standard SQL doesn't allow to include non-aggregated columns when using GROUP BY, I guess this is one of the reasons).
From your description of the what you want to do, you should simple SELECT all rows with the lang you are looking for
SELECT * FROM your_table WHERE lang = 1