Selecting multiple values from another table on SQL (phpMyAdmin) - sql

I've been trying to select multiple values from another table (i.e. texts in multiple rows) and display it on main table so that multiple values can be on one cell.
(also, I don't speak English, so some terms might sound different, sorry)
Example:
1st table:
ID
Name
Value1
1
Cell 2
A; B
2
Cell 4
B;C;D
2nd table (column Value1 is connected to the previous table's Value1 column):
ID
Value1
1
A
2
B
3
C
4
D
5
E
So in the first table I want to put both values in one cell from the 2nd table
Thank you!
At the moment, I am able to select only one value for Value1 column in the first table that is referenced to the second table.
On phpMyAdmin, I tried to add several columns on one constraint, but error occurred.

Related

Insert distinct values from another table's column on to a new table BigQuery

I am trying to write a BigQuery to get distinct values from one table say ABC
select distinct name from dataset.abc
1
2
3
4
now I want to insert these values to another table say XYZ, which also contains column as name and another column as company.
Note: the company column can be duplicated as I want the to have all 4 rows against every company to be inserted in table ABC.
I need a BigQuery to do this dynamically instead of updating every dataset manually every time.
P.S. Sorry if my question is not as per standards as this is the first time I am posting on Stackoverflow.

Postgres Ordering by subquery/multiple subqueries

I have four models: Table, Column, Row, Cell. A Cell belongs to a Row and a Column, both of which belong to a Table. The UI of this looks like your typical table view, the values displayed being those of the Cells.
Cells have a value. Each Table also has one Column of type 'key', whose Cell's values are unique.
Columns can be relational-type, meaning their Cell's values reference the Cells in the key Column of a different Table, the linked Table. This way, a relational Cell will actually 'belong to' a Row from the linked Table since key values are unique.
For relational-type Cells, the value used for display isn't the value stored in the Cell (a value from the linked table's key Column). We let the user choose a Column from the linked Table as the 'display column', and those values are the ones used for display in this Table's relational Column.
Normally we order Rows by the plain old Cell values in the Column chosen for ordering. However, when ordering by a relational-type Column, we want to order by their Cell's display value. This means for each Row, we need to find the value stored in the relational Cell (a key value from the linked Table), find the corresponding Row from the linked Table whose key Column's Cell matches that value, then find the value of that Row's display Column's Cell, then order by that value.
Some sample values.
Table 1
Column 1 (key) | Column 2
1 | b
2 | a
3 | c
Table 2
Column 2 links to Table 1. This means it stores the key values from Table 1, but currently uses the values from Table 1's Column 2 as its display column.
Actual values in Table 2:
Column 1 (key) | Column 2 (relational)
4 | 1
5 | 2
6 | 3
What's displayed:
Column 1 (key) | Column 2 (relational)
4 | b
5 | a
6 | c
Post ordering, Table 2 should look like:
Column 1 (key) | Column 2 (relational)
5 | a
4 | b
6 | c
I will be frank: I have absolutely no idea how to construct this SQL query/subqueries. Any suggestions pointing me in the right direction would be very much appreciated.
If I am following correctly, you want a join and order by:
select t2.column1, t1.column2
from table2 t2 join
table1 t1
on t2.column2 = t1.column1
order by t1.column2

Database lookup in Talend

In my talned job I am copying data from Excel to SQL table.
For this job to maintain the foreign key constraint I had to do a look up before copying the data.
The task goes like this.
I have to copy data in Table2 (id keys value).
My excel sheet has data for id and keys column. Table 1 has two columns id and value.
For value column's data I want to look at Table1's corresponding entry with the id of the current record in Table2. I have to copy the data from Table1's value column to Table2's value column.
Excel (id 1 2 3, keys a b c)
Table_1 (id 1 2 3, value 123 456 789)
desired output: Table_2 (id 1 2 3, keys a b c, value 123 456 789)
current output: Table_2 (id 1 2 3, keys a b c, value null null null)
How do I properly map this?
You've set the job up exactly as needs to be done really so it's not your job layout that's the problem here.
If you're expecting every record in your Excel document to have a matching record in your database table then you should use an inner join condition in your tMap join like so:
And this then allows you to have an output that grabs everything that isn't joining (which is your issue here):
This should show you everything in your source (not lookup) file that isn't matching. I suspect that everything is failing to match on your join condition (essentially WHERE ExcelDoc.id = Table.Id) even if it looks like it should. This could be down to a mismatch of datatypes as they are read into Talend (so the Java/Talend datatypes such as int/Integer or String rather than the DB types) or because one of your id columns has extraneous whitespace padding.
If you find that your id column in one of your sources does in fact have any padding then you should be able to convert it in a previous step before your join or even just make the transformation in the join:
The only other thing I'd recommend is that you name your flows between components (just click on them to change the name), especially when you are joining anything in a tMap.

Select single row from database table with one field different and all other being same

I have a database table with 8 fields say Table(a,b,c,d,e,f,g,h).For some rows one of the field is different(say 4 different a values) while all other field values(b-h) in the schema are same.I have to make a table selecting just one rows from such rows with different a's but same b-h.That is I can select any one of the different a's and keep b-h same which they are and display it in table as 1 single row instead of 4.
SELECT MIN(a) a,b,c,d,e,f,g,h
FROM mytable
GROUP BY b,c,d,e,f,g,h

How to replicate a table 100 times and add it back to the original table

I just started using SQL and need to perform the following task.
1) First, I need to dupicate a table 100 times. For all these duplicated tables, I want to keep its content unchanged. But I also want to update the primary key by one.
2) Secend, I want to concatenate all these duplicated tables together by row, and also concatenate them to the original table by row.
Example: The original table looks like:
ID CATEGORY
1 A
2 B
… …
26 Z
And I want to duplicate this table, and concatenate it to the original one. I want to maintain the colums other than the primary key (ID here) unchanged, and update the primary key by one each time. I want to get:
ID CATEGORY
1 A
2 B
...
26 Z
27 A
...
52 Z
How to do this? Thanks!