Reputation: 66
I'm looking for help with a formula. I'm looking for how to do two separate SELECT queries, but without merging them so.
SELECT basetype from table1 where name="test";
**SELECT itemid from table2 where itemid="5";**
I want the query to display basetype as a column and itemid as another column. Short version is two selects in one query displaying results. Data doesn't have to match between the tables.
EDIT: I screwed up. It's two separate tables. The results I want is basically this.
No union.
BASETYPE | ITEMID
1 | 5
Upvotes: 0
Views: 182
Reputation: 1270091
I suspect you want this:
select rn, max(basetype) as basetype, max(itemid) as itemid
from ((SELECT @rn := @rn + 1 as rn, basetype, NULL as itemid
from table1 cross join
(select @rn := 0) var
where name = 'test'
) union all
(SELECT @rn2 := @rn2 + 1, NULL, itemid
from table2 cross join
(select @rn2 := 0) var
where itemid = '5'
)
) t
group by rn;
Upvotes: 2
Reputation: 651
Try this:
SELECT basetype, itemid
FROM table1
where table1.name="test" AND table1.itemid="5";
Upvotes: 0
Reputation: 433
One method would be to create subqueries.
SELECT a.basetype, b.itemid FROM
(SELECT basetype from table1 where name="test") a,
(SELECT itemid from table1 where itemid="5") b
Upvotes: 0
Reputation: 1117
You have two options, either UNION or using subqueries (also known as subselects). I think you're looking for UNION.
SELECT column_name(s) FROM table1
UNION
SELECT column_name(s) FROM table2;
Upvotes: 0
Reputation: 37233
Try with union :
SELECT basetype from table1 where name="test"
union
SELECT itemid as basetype from table1 where itemid="5";
Upvotes: 0