Reputation: 43
I have MySQL 2 Table like this
Table_1
Table_2
And i want result table like this
Result Table
So, I put this query
SELECT A.TAG,B.VALUE
FROM TABLE_1 A
LEFT JOIN TABLE_2 B
On A.CODE=B.CODE;
And can i create automatic map field when i want this result table i just call
SELECT TAG,VALUE FROM MAP_TABLE WHERE TAG IN('ASSX','ASPS','AAPP');
Upvotes: 2
Views: 1756
Reputation: 25351
You look like trying to use sub-query like this:
SELECT tag, value
FROM (SELECT a.tag, b.value
FROM table_1 a
LEFT JOIN table_2 b On a.code = b.code)
WHERE tag IN('ASSX','ASPS','AAPP');
However, you can simply add the condition to your first query:
SELECT a.tag, b.value
FROM table_1 a
LEFT JOIN table_2 b On a.code = b.code
WHERE a.tag IN('ASSX','ASPS','AAPP');
Upvotes: 1
Reputation: 655
Did you try nested selects?
SELECT tag ,value FROM
( SELECT A.TAG as tag ,B.VALUE as value
FROM TABLE_1 A
LEFT JOIN TABLE_2 B
On A.CODE=B.CODE;)
WHERE tag IN('ASSX','ASPS','AAPP');
Other solution: Creating new table from query.
create table map_table(
tag varchar(255),
value int);
And then filling this table with your needed values:
INSERT INTO map_table
(SELECT A.TAG as tag ,B.VALUE as value
FROM TABLE_1 A
LEFT JOIN TABLE_2 B
On A.CODE=B.CODE;)
Upvotes: 2