1

I have 3 table. I want to select the data from them order by date. I'm saving the date in unixtimestamp in all table. I'm using the following query:

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 structure is: cover_pic table:

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

wp_friends table:

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

wp_userstatus table:

id  status   display_name  userid  userid1  postdate    
6   awesome  paramveer     4       4        1352414658
7   lets     paramveer     4       4        1352414932

It is showing the following error:

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

I want to show the data in order by date.

5
  • 1
    and what's the problem with your current query? Commented Nov 16, 2012 at 13:16
  • What output do you want? Commented Nov 16, 2012 at 13:17
  • Use joins to make your query readable. Commented Nov 16, 2012 at 13:19
  • it is showing the following error#1142 - SELECT command denied to user 'kdgadget'@'localhost' for table 'cover_pic' Commented Nov 16, 2012 at 13:20
  • Is kdgadget database name or db user name? Commented Nov 16, 2012 at 13:24

4 Answers 4

2

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

should be a clear message. User kdgadget may not execute a SELECT command on table cover_pic. So it's a database configuration issue, not a query one.

Sign up to request clarification or add additional context in comments.

Comments

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

but each table must be same length, size.

Comments

0

Use this query which uses joins and alias of tables are organized:

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

Your error is not from sql. User don't have permissions to execute select. See error solving posts:

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

Comments

0

One of the possible cause may be by using the incorrect database or schema name.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.