Is it possible to use if -> where in MySQL? -


i have list of templates user creates data (type of data not important). templates stored in table have field private of enum type values 0, 1 means false/true. main idea each user can create private template can see him, other templates can see system users. sql should this:

select     `templates`.`id`,     `templates`.`name`,     `templates`.`description`,     `templates`.`datetime`,     `users`.`username`     (`templates`) join `users` on `templates`.`user_id` = `users`.`id` --     -- `users`.`id` <> 1 , `templates`.`private` = 0 order     `templates`.`datetime` desc limit 5 

in where need rows except private not id, miss own private templates...

there seems no reason join users table. can public , own private templates

select     `templates`.`id`,     `templates`.`name`,     `templates`.`description`,     `templates`.`datetime`,     `templates`     `templates`.`user_id` = 42 or `templates`.`private` = 0 

i assuming id of current user 42, substitute real value when constructing query.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -