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.

fthiella
  • 48,073
  • 15
  • 90
  • 106
user1734190
  • 157
  • 1
  • 2
  • 12

4 Answers4

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.

Cravid
  • 653
  • 2
  • 7
  • 22
0
(SELECT * from in_order where `id` = '$id')
UNION
(SELECT * from pre_order where `id` = '$id')

but each table must be same length, size.

guybennet
  • 683
  • 1
  • 9
  • 25
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
Community
  • 1
  • 1
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
0

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

Vaibs
  • 2,018
  • 22
  • 29