문제

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
도움이 되었습니까?

해결책

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;

다른 팁

Try with union :

 SELECT basetype from table1 where name="test"
 union 
 SELECT itemid  as basetype from table1 where itemid="5";

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;

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

Try this:

 SELECT basetype, itemid
 FROM table1
 where table1.name="test" AND table1.itemid="5";
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top