I have Two column:
Col1 Col2
A D
B E
C F
I want in expression to join columns and get
Col
A
B
C
D
E
Any idea?
T1:
LOAD * INLINE [
Col1
A
B
C
];
T2:
LOAD * INLINE [
Col2
D
E
F
];
T:
Load
Col1 as Col
Resident T1;
Load
Col2 as Col
Resident T2;
drop tables T1,T2;
You don't explain that, but I'll assume that Col1 and Col2 are part of the same table, like this :
BASETABLE:
LOAD * INLINE [
Col1,Col2
A,D
B,E
C,F
];
You can then, using the fact that Qlikview assumes that the same column name is the same data to do this :
NEWTABLE:
LOAD Col1 as Col Resident BASETABLE;
LOAD Col2 as Col Resident BASETABLE;
The NEWTABLE will have a single column with data from Col1 and Col2.
Related
I have the following oracle sql query:
SELECT DISTINCT A, B, C, D
FROM my_table
WHERE (B IN (SELECT ID_X FROM table2))
This is fine because B is in table2.
Now I would like to query for column D which is not in table2 but can be mapped from my_table via D.
Table "my_table":
A
B
C
D
abc
def
ghi
jmk
Table "table2":
B
value
def
2
How can I first extract the value of column B if I only have the value of column D:
jmk -> def
And then use that value to extract my data from table2:
def -> 2
Use an inner join:
SELECT DISTINCT t1.*, t2.value
FROM my_table t1
INNER JOIN table2 t2
ON t2.ID_X = t1.B;
With your sample data:
WITH
tbl AS ( Select 'abc' "A", 'def' "B", 'ghi' "C", 'jmk' "D" From Dual ),
tbl_1 AS ( Select 'def' "B", 2 "VALUE" From Dual )
try this:
SELECT t.A, t.B, t.C, t.D, t1.VALUE "VALUE_OF_B"
FROM tbl t
LEFT JOIN tbl_1 t1 ON(t1.B = t.B)
WHERE t.D = 'jmk'
R e s u l t :
A B C D VALUE_OF_B
--- --- --- --- ----------
abc def ghi jmk 2
If there is no match of column B in tbl_1 you will get the row where VALUE_OF_B is null. If you put INNER instead of LEFT JOIN then, without the match, no rows will be selected. It's up to you to decide what kind of join to use...
I'm working in SQL and have the following table (named table1):
col1
col2
D
A
E
A
F
A
G
B
H
B
I
B
J
C
K
C
L
C
and I would like it to return:
col1
col2
D
A
G
B
J
C
I am looking for an SQL query that returns the first value in col1 for each distinct value in col2. Basically I am looking to only retrieve one value for each distinct value in col2 and remove any duplicates in col2. I am looking for a query that I would be able to apply to other tables where I might not know the positions of the distinct values. Thanks for in advance for any help!
Try the following:
SELECT MIN(col1) col1, col2 FROM table1
GROUP BY col2
I'm trying to achieve what's in the example, the idea is to get data from table B if it exists and that with respec to the columns col1=col3 and col2=col4.
not sure wether this is possible or not using SQL
col1 col2
a b
c d
e f
Table B:
col3 col4
NULL x
y NULL
NULL NULL
Final_Table:
col1 col2
a x
y d
e f
You need to have a primary key to compare two or more tables. It is not possible if there is no primary key.
I have two tables A and B which look like this:
Table A
col1 col2 ID
--------------
a b 1
c d 2
Table B
col3 col4 ID
--------------
x t 1
y u 1
z o 2
m n 2
I want to create this new table:
Table C
col1 col2 col3 col4 ID
-------------------------
a b x t 1
a b y u 1
c d z o 2
c d m n 2
The ID's in A are not the unique ID's of those elements in that list. I just need to add a few more properties from their "parent" table(B) in this new table. I know there will be a lot of repetitions but I don't mind that for now.
I tried this following statement:
INSERT INTO C(SELECT A.*, B.col1, B.col2 from A LEFT OUTER JOIN B ON (B.ID = A.ID));
But it is resulting in something I did not expect. The row count of C must be the same as the row count of B. However when I used this SQL query, the resulting tables row count was even more than the total row count of A and B. I'm a beginner in using SQL I would appreciate any help.
A basic JOIN will do:
select
a.col1,
a.col2,
b.col3,
b.col4,
a.id
from tablea a
join tableb b on a.id = b.id
If I got you right your tables do not have any relation to each other.
So in this case you should be able to do something like this?
Select * from table1, table2
You can also combine this with an insert so you should get your new table
While working on a oracle SQL , noticed that adding a column to the selected columns increases the total rows in the result. The query is using multiple subqueries declared using WITH. The join in the final query is a left join. Why is the row count getting impacted?
The only way I can think of to increase the number of result rows by adding a column to the SELECT clause is when using SELECT DISTINCT.
SELECT DISTINCT removes duplicates from the results, so
col1 col2
a b
a b
a c
a c
becomes
col1 col2
a b
a c
When adding a column
col1 col2 col3
a b d
a b e
a c f
a c f
becomes
col1 col2 col3
a b d
a b e
a c f
for instance, which is one row more than before.