2012-11-16 6 views
1

테이블이 3 개 있습니다. 날짜순으로 데이터를 선택하고 싶습니다. 나는 모든 테이블에 unixtimestamp에 날짜를 저장하고 있습니다.여러 테이블에서 데이터를 선택하는 SQL 쿼리

select 
    c.up_date, c.user_id, c.id, 
    f.id, f.up_date, f.friend1, f.friend2, f.status, 
    s.postdate, s.status, s.id, s.display_name, s.userid, s.userid1 
from 
    c.cover_pic, 
    s.wp_userstatus, 
    f.wp_friends 
where 
    s.userid=c.friend1 
    and s.userid=c.user_id 
    and f.status=1 
    and c.user_id=4 
order by s.postdate 

Tablel 구조는 다음과 같습니다 : cover_pic 테이블 :

id user_id coverpic        color up_date 
1 4   496b02165600889daf51c6b04b257ec0.jpg 63ACFF 1353069741 

wp_friends 테이블 :

id friend1 friend2 status up_date 
12 1 4 2  1353064093 
11 4 1 1  1353064093 

wp_userstatus 테이블 :

나는 다음과 같은 쿼리를 사용하고 있습니다
id status display_name userid userid1 postdate  
6 awesome paramveer  4  4  1352414658 
7 lets  paramveer  4  4  1352414932 

하면 다음과 같은 오류를 보여주고있다 :

#1142 - SELECT command denied to user 'kdgadget'@'localhost' for table 'cover_pic' 

내가 날짜 순서로 데이터를 표시합니다.

+1

현재 검색어에 어떤 문제가 있습니까? –

+0

원하는 출력은 무엇입니까? – Arion

+0

조인을 사용하여 쿼리를 읽을 수있게 만듭니다. – Farfarak

답변

0
(SELECT * from in_order where `id` = '$id') 
UNION 
(SELECT * from pre_order where `id` = '$id') 

각 표는 동일한 길이, 크기 여야합니다.

0

사용은 사용이 쿼리 조인 및 테이블의 별칭은 구성되어 있습니다

select c.up_date,c.user_id,c.id,f.id,f.up_date,f.friend1,f.friend2,f.status, 
s.postdate, s.status,s.id,s.display_name.s.userid,s.userid1 
from cover_pic as c JOIN wp_userstatus as s, 
ON s.userid=c.friend1 and s.userid=c.user_id and c.user_id=4 
JOIN wp_friends as f ON f.status=1 
order by s.postdate 

귀하의 오류가 SQL에서이 아니다. 사용자에게 select를 실행할 수있는 권한이 없습니다. 참조 오류 해결 게시물 :

  1. User cannot execute select error 1142
  2. ERROR 1142 (42000): ALTER command denied
  3. MySQL Error: #1142 - SELECT command denied to user
+0

작동하지 않습니다. – user1734190

2

SELECT command denied to user 'kdgadget'@'localhost' for table 'cover_pic'

는 분명한 메시지 있어야한다. 사용자 kdgadget이 cover_pic 테이블에서 SELECT 명령을 실행하지 못할 수 있습니다. 데이터베이스 구성 문제이므로 쿼리가 아닙니다.

0

잘못된 데이터베이스 또는 스키마 이름을 사용하여 발생할 수도 있습니다.

관련 문제