2016-10-04 2 views
-1

테이블 치과 열이 (제목, 게시자, 키워드, 제목)이고 다른 테이블이 있습니다 (저자, 제목, 저널, 발행인, 요약 , 키워드) 및 세 번째 테이블 현자 열은 (저자, 제목, 저널, 발행인, 요약, 키워드)입니다. 질문은 어떻게 내가 모든 세 테이블에서 데이터베이스에서 데이터를 얻을 수있는 모든 노동 조합을 통해 이러한 테이블을 결합 할 수 있습니다.다른 열이있는 다중 테이블과 결합하는 방법

select null author, Title, null journal, publisher, subject as abstract, keyword from table1 
    union 
select author, title, journal, publisher, abstract,keyword from table2 

select null author,Title,null journal,publisher,null abstract,subject as abstract,keyword from dental 
    where (Author LIKE '%Bastone%' or Title LIKE '%Bastone%' or Journal LIKE '%Bastone%' 
     or Publisher LIKE '%Bastone%' or abstracts LIKE '%Bastone%' or Keyword LIKE '%Bastone%' 
     or Title LIKE '%Bastone%' or Publisher LIKE '%Bastone%' or Keyword LIKE '%Bastone%' 
     or Subject LIKE '%Bastone%') 
    union 
select author, title, journal, publisher, abstract,keyword, null subject from elsevier 
    where(Author LIKE '%Bastone%' or Title LIKE '%Bastone%' or Journal LIKE '%Bastone%' 
     or Publisher LIKE '%Bastone%' or abstracts LIKE '%Bastone%' or Keyword LIKE '%Bastone%' 
     or Title LIKE '%Bastone%' or Publisher LIKE '%Bastone%' or Keyword LIKE '%Bastone%' 
     or Subject LIKE '%Bastone%') 

이 오류

#1054 - Unknown column 'Author' in 'where clause'
+0

봐 (HTTP : // 유래 .com/questions/15867152/mysql-union-different-of-columns? rq = 1). 나는 그들의 접근 방식 ("null"값을 겹치지 않는 컬럼에 대해 제안한다.) – Insac

+0

두 테이블 모두 다른 수를 가지고 있기 때문에 –

+0

컬럼의 다른 숫자를 가질 수있다. 그러나 접근법은 일반화 될 수있다 .. 아래에 제안 된 대답을 보라 – Insac

답변

0

가능한 접근법은 다음과 같습니다.

select null author, Title, null journal, publisher, null abstract, keyword, subject 
    from table1 
union all 
select  author, title,  journal, publisher,  abstract,keyword, null subject 
    from table2 
union all 
select  author, title,  journal, publisher, abstract,keyword, null subject 
    from table3 

일부 필드가 단지 "동의어"(예 : 추상 및 주제)를 사용하면 앨리어스 (예 : '추상적 인 주제')와 같이 동일한 열에 반환 할 수 있습니다. 예를 들어 아래 참조 : 설명 후

select null author, Title, null journal, publisher, subject as abstract, keyword 
    from table1 
union all 
select  author, title,  journal, publisher,  abstract,keyword 
    from table2 
union all 
select  author, title,  journal, publisher, abstract,keyword 
    from table3 

를 쿼리

의 구조에 당신이 결과 테이블에 조건이 더 나은 쿼리로 포장 것 어디를 적용 한 후 필요한 경우.

예 :

select * from (
    select null author, Title, null journal, publisher, subject as abstract, keyword 
     from table1 
    union all 
    select  author, title,  journal, publisher,  abstract,keyword 
     from table2 
    union all 
    select  author, title,  journal, publisher, abstract,keyword 
     from table3 
) as table_union 
where author like '%string%' 

어떤 이유로, 당신은 전체 쿼리를 쌀 수 없습니다, 경우 (즉, 귀하의 질의 프레임 워크의 제한을 위해), 당신은 하나의 쿼리를 포장 할 수있다.

그래서, 원래 쿼리가 기록 될 수 등 :

select * from (
select null author, Title, null journal, publisher, null abstract, keyword, subject 
    from dental 
union all 
select  author, title,  journal, publisher,  abstract,keyword, null subject 
    from elsevier 
) as table_union 
where (Author LIKE '%Bastone%' 
     or Title LIKE '%Bastone%' 
     or Journal LIKE '%Bastone%' 
     or Publisher LIKE '%Bastone%' 
     or abstract LIKE '%Bastone%' 
     or Keyword LIKE '%Bastone%' 
     or Subject LIKE '%Bastone%' 
) 

나 : "열 MySQL의 조합 다른 번호"]에 대한 대답에서

select * from (
select null author, Title, null journal, publisher, null abstract, keyword, subject 
    from dental 
) as dental_2 
where (Author LIKE '%Bastone%' 
     or Title LIKE '%Bastone%' 
     or Journal LIKE '%Bastone%' 
     or Publisher LIKE '%Bastone%' 
     or abstract LIKE '%Bastone%' 
     or Keyword LIKE '%Bastone%' 
     or Subject LIKE '%Bastone%' 
) 

union all 

select * from (
select  author, title,  journal, publisher,  abstract,keyword, null subject 
    from elsevier 
) as elsevier_2 
where (Author LIKE '%Bastone%' 
     or Title LIKE '%Bastone%' 
     or Journal LIKE '%Bastone%' 
     or Publisher LIKE '%Bastone%' 
     or abstract LIKE '%Bastone%' 
     or Keyword LIKE '%Bastone%' 
     or Subject LIKE '%Bastone%' 
) 
+0

# 1054 - 'where 절'의 '작성자'알 수없는 열이 mysql에서이 오류가 발생했습니다. –

+0

테스트중인 코드를 붙여 넣으시겠습니까? 혼합 된 사례 이름을 강요하고 있습니까? – Insac

+0

내가 u 쿼리를 게시 할 수 있습니다. 내가 구조를 만들었습니다. –

0

에게 점점 : 난 내가 사용할 때이

에 관한 모든 솔루션이있는 경우 경우 노동 조합이 너무 좋습니다에만 옵션에 가입 사용할 수 없습니다 두 번째 테이블과 세 번째 테이블에 대한 별칭 이름을 첫 번째 테이블 필드로 사용합니다.

+0

ui 구조를 보내 주실 수 있습니까 ??? –

+0

(저자로 null 선택, 저널, 게시자, 게시자로 null, 게시자로 null, 요약, 키워드, 치과에서 null로 1) union (저자, 제목, 저널, 발행인, 요약, 키워드, 발행인, 키워드 from elsevier 1) –

+0

# 1054 - 'where 절'의 '작성자'알 수없는 열이 오류가 발생합니다. 1) union (작성자로 null을 선택하고, Title, null을 저널, 게시자, null로 요약, 키워드, –

관련 문제