Reputation: 1632
I am using query for get json result. Its working fine but now I want only result fetched where qu_status=1 in table quotes. But I am not able to make it working. My working query without check above condition is like below
$sql = "SELECT q.*,c.au_picture as picture FROM tbl_quotes q INNER JOIN tbl_category c ON q.qu_author=c._auid Order By q.".$orde." Desc LIMIT ".$limit." OFFSET ".$offset;
I have tried to use it like below
$sql = "SELECT q.*,c.au_picture as picture FROM tbl_quotes where qu_status=1 q INNER JOIN tbl_category c ON q.qu_author=c._auid Order By q.".$orde." Desc LIMIT ".$limit." OFFSET ".$offset;
But I am wrong somewhere in this and so I can not getting any result. Let me know if someone can correct me. Thanks
Upvotes: 0
Views: 38
Reputation: 324
Try to put the where
condition behind the join.
Also prefix your condition with your defined alias q
.
...
where q.qu_status = 1
...
Upvotes: 0
Reputation: 133370
the where clause must be after the join so
$sql = "SELECT q.*,c.au_picture as picture
FROM tbl_quotes q
INNER JOIN tbl_category c ON q.qu_author=c._auid
where q.qu_status=1
Order By q.".$orde." Desc LIMIT ".$limit." OFFSET ".$offset;
or you can do directly in join avoiding where
$sql = "SELECT q.*,c.au_picture as picture
FROM tbl_quotes q
INNER JOIN tbl_category c ON q.qu_author=c._auid and q.qu_status=1
Order By q.".$orde." Desc LIMIT ".$limit." OFFSET ".$offset;
Upvotes: 1