How to display unique records in the result after left join in pentaho Data integraion - unique

Table input enter image description here
ID
Code
Amt
PK
ALI
DE000A3MQYU1
NFID
10000
123
jj
DE000A3MQYU1
NFID
234
124
jj
Another input enter image description here
ID
Code
FK
DE000A3MQYU1
NFID
1
DE000A3MQYU1
NFID
2
Expected Result :
enter image description here
ID
Code
Amt
PK
ALI
FK
DE000A3MQYU1
NFID
10000
123
jj
1
DE000A3MQYU1
NFID
234
124
jj
2
I tried stream lookup but it will give only either high or low value from another stream but iam expecting below output enter image description here
ID
Code
Amt
PK
ALI
FK
DE000A3MQYU1
NFID
10000
123
jj
1
DE000A3MQYU1
NFID
234
124
jj
2

Related

SELECT DATA from many to many tables without repetead

i have this project where i need to show this table on a webpage:
Result Table (one Bill can have one or many PurchaseOrder)
BILLID
DESCRIPTION
PO
PO_DESCRIPTION
HES
1
BILLING1
1001,1002
TEST1,TEST2
ABC,DFG
2
BILLING2
1003
TEST3
HIJ
Which its created based on 4 tables:
BillingTable
BILLID
DESCRIPTION
CREATEDAT
1
BILLING1
2022-01-03
2
BILLING2
2022-01-14
BillingPos Table (it had a relationship with BillingTable (many-to-one) and with HesTable (one to many)
ID
FK_BILLID
FK_HES_ID
CREATEDAT
1
1
1
2022-01-03
2
1
2
2022-01-03
3
2
3
2022-01-14
Hes Table: it have a relationship with PurchaseOrder Table
ID
HES_ID
FK_PO_ID
CREATEDAT
1
ABC
1
2022-01-01
2
DFG
2
2022-01-01
3
HIJ
3
2022-01-01
PurchaseOrder Table
ID
PURCHASEORDER
DESCRIPTION
CREATEDAT
1
1001
TEST1
2022-01-01
2
1002
TEST2
2022-01-01
3
1003
TEST3
2022-01-01
I Know i have to use GROUP_CONCAT to concatenate the POs, Description and HES in one row for the billing id but i canĀ“t figure it out
Consider:
SELECT Billing.BillID, Billing.Description, Group_Concat(PurchaseOrder) AS PO,
Group_Concat(PurchaseOrder.Description) AS PO_Description, Group_Concat(HES_ID) AS HES
FROM Billing INNER JOIN (PurchaseOrder
INNER JOIN (HES INNER JOIN BillingPos
ON HES.ID = BillingPos.FK_HES_ID)
ON PurchaseOrder.ID = HES.FK_PO_ID)
ON Billing.BillID = BillingPos.FK_BilledID
GROUP BY BillID, Billing.Description;

I am trying to return combined rows in the same table based on a key in a second table

I probably haven't explained this very well in the title but I have two tables. Here is a simple version.
channel_data
entry_id channel_id first_name last_name model other_fields
1 4 John Smith
2 4 Jane Doe
3 4 Bill Evans
4 15 235
5 15 765
6 15 543
7 15 723
8 15 354
9 15 976
10 1 xxx
11 2 yyy
12 3 123
channel_titles
entry_id author_id channel_id
1 101 4
2 102 4
3 103 4
4 101 15
5 101 15
6 101 15
7 102 15
8 102 15
9 103 15
10 101 1
11 102 2
12 103 3
I am not able to re-model the data unfortunately.
I need to list all the rows with a channel_id 15 from channel_data and beside them the first_name and last_name which has the same author_id from channel_titles.
What I want to return is this:
Model First Name Last Name
---------------------------------
235 John Smith
765 John Smith
543 John Smith
723 Jane Doe
354 Jane Doe
976 Bill Evans
If Model was in one table and Names were in another this would be much simpler but I'm not sure how to go about this when they are in the same table.
========================================
Edited to clarify.
I need to get each model with a channel_id 15 from channel_data
For each model I need to look up the entry_id in channel_titles to find the author_id
I need to find the row with that author_id AND channel_id 4 in channel titles (each row with channel_id 4 has a unique author_id).
I need to take the entry_id of this row back to channel_data and get the first_name and last_name to go with the model.
I am well aware that the data is not structured well but that is what I have to work with. I am trying to accomplish a very small task in a much larger system, remodelling the data is not an option at this point.
I think sub-queries might be what I am looking for but this is not my area at all usually.
Ok, that is convoluted. However, based on your description, this query should give you the results you want. The WHERE and JOIN descriptions follow the logic you have described in your question.
SELECT cd1.model, cd2.first_name, cd2.last_name
FROM channel_data cd1
JOIN channel_titles ct1 ON ct1.entry_id = cd1.entry_id
JOIN channel_titles ct2 ON ct2.channel_id = 4 AND ct2.author_id = ct1.author_id
JOIN channel_data cd2 ON cd2.entry_id = ct2.entry_id
WHERE cd1.channel_id = 15
ORDER BY cd1.entry_id
Output:
model first_name last_name
235 John Smith
765 John Smith
543 John Smith
723 Jane Doe
354 Jane Doe
976 Bill Evans
Demo on SQLFiddle

I'm trying to create dynamic SQL in MySQL

I use MySql and I have some problems with it ^^
Let's say I have two tables which will be "FirstTable" and "SecondTable"
First table (ID isn't the primary key)
ID IdCust Ref
1 300 123
1 300 124
2 302 345
And the second (ID isn't the primary key)
ID Ref Code Price
1 123 A 10
1 123 Y 15
2 124 A 14
3 345 C 18
[EDIT] The column "Stock" in the final result is equals to "ID" in the second table
The column "Stock", "Code" and "Price" can have x values, so I don't know it, in advance...
I make some research in stackoverflow, but I only find post where people use "count(case when ..."
Like this one : MySQL pivot row into dynamic number of columns
For my problem, I cannot use it, because i can't know in advance the value of reference
I'm trying to produce the following output:
The result I want
[EDIT] Result in TXT
ID IdCust Ref StockA Code1 Price1 StockB Code2 Price2
1 300 123 1 A 10 1 Y 15
1 300 124 2 A 14
2 300 345 3 C 18

How to change record in table with consecutive value?

I have table like below :
Application_Number Id_Number1 Name
1 123 John
2 456 Alan
3 789 Charlie
4 111 Patrick
5 222 Robert
Then i would like to update record in one of rows become like this :
Application_Number Id_Number1 Name
1 123 Alias 1
2 456 Alias 2
3 789 Alias 3
4 111 Alias 4
5 222 Alias 5
if i have more than one million record do i need update syntax or any another way? I'm using SQL2008
Thanks
Select Application_Number
,Id_Number1
,'Alias' + CAST( ROW_NUMBER()
OVER (ORDER BY Application_Number) AS Varchar) AS Name
FROM Table Name

Select rows with matching columns in other tables

I have 3 tables and I want to query them and get results based on
Table 1 Team ID .
I think its simple but I failed to work this out.
All I'm trying to do is get their select their data from other tables and group them by TeamID.
The structure of tables is as follows:
Table 1
This table holds the teams entries by PersonID - referenced by PersonID Table, Each team is in one row
[TeamID] Tournament_id Person_1_ID Person_2_ID Person_3_ID Country_ID
--- --------- -------- ---------- --------- --------
1 77789 123 124 125 90
2 77789 126 127 128 95
3 77789 129 130 131 5
.........
Table 2
This is the person table PersonID = Primary Key
[PersonID] Name Dob Email Country_ID
--------- ------- -------- ---------- ------------
123 John 19/03/1992 John#live.com 90
124 Moe 20/10/1995 Moe#live.com 90
125 Sami 10/05/1989 Sami#example.com 90
126 Kim 30/01/1990 Kim#company.com 95
.......
Table 3
Participation table
[ParticipationID] PersonID tournament_id Country_id
----------------- ---------- ------------- -------------
9999901 123 77789 90
9999902 124 77789 90
9999903 125 77789 90
9999904 126 77789 95
9999905 127 77789 95
.......................
How do I get this output
TeamID Tournament_Id Name Country_ID
------ ----------- ----- ------
1 777789 John 90
1 777789 Moe 90
1 777789 Sami 90
2 777789 Kim 95
Something like this:
SELECT t.TeamID
,t.Tournament_Id
,pr.Name
,pr.Country_Id
FROM Team AS t
INNER JOIN Participation AS p ON p.tournament_id = t.Tournament_id
INNER JOIN Person AS pr ON pr.PersonID = p.PersonID
WHERE Tournament_Id = 777789