Saef Myth
Saef Myth

Reputation: 297

msyql multiple where statements

SELECT
                              `pid`,
                              `uid`,
                              `created_date`,
                               UNIX_TIMESTAMP(`created_date`) as created_date_timestamp,
                              `updated_date`,
                              `post_status`,
                              `post_visibility`,
                              `post_content_availability`,
                              `content`,
                              `images_count`,
                              `videos_count`,
                              `media_availability`,
                              `images_availability`,
                              `videos_availability`
                              `up_count`,
                              `down_count`,
                              `comments_count`,
                              `comments_availability`,
                              `post_type`,
                              `post_max_date`,
                              `contans_feeling`,
                              `contans_activity`,
                              `feeling_type`,
                              `activity_type`,
                              `activity_about`,
                              `post_hashtag`,
                              `currency_type`,
                              (SELECT CONCAT(`first_name`, ' ', `last_name`)  FROM `users` WHERE `uid` = t1.`uid` LIMIT 1) AS user_name,
                              IFNULL((SELECT `upid` FROM `post_ups` WHERE `pid` = t1.`pid` AND `uid` = '$uid' AND `up_status` = 1 LIMIT 1),'-1') AS ups_status,
                              IFNULL((SELECT `upid` FROM `post_downs` WHERE `pid` = t1.`pid` AND `uid` = '$uid' AND `down_status` = 1 LIMIT 1),'-1') AS downs_status,
                              (SELECT `file_name` FROM `profile_images` WHERE `uid` = t1.`uid` AND `active` = '1' LIMIT 1) AS profile_image,
                              (SELECT CONCAT(
                                '[',
                                                    GROUP_CONCAT(json_object('image_width',image_width,'image_height',image_height,'image_name', image_name, 'iid', iid)),
                                ']'
                            )
                            FROM posts_images WHERE pid = t1.`pid`) AS posts_images,
                            (SELECT CONCAT(
                                '[',
                                                    GROUP_CONCAT(json_object('video_name', video_name, 'vid', vid)),
                                ']'
                            )
                            FROM posts_videos WHERE pid = t1.`pid`) AS post_videos,
                            IFNULL(
                                                    (SELECT
                                                    CONCAT('{','username:\"',
                                                        (SELECT CONCAT(`first_name`, ' ', `last_name`)  FROM `users` WHERE `uid` = t4.`uid` LIMIT 1) ,'\",',
                                                           'comment_content:\"',
                                                      `comment_content`,'\",',
                                                           'profile_image:\"',
                                                       (SELECT `file_name` FROM `profile_images` WHERE `uid` = t4.`uid` AND `active` = '1' LIMIT 1),'\"}')
                                                    FROM
                                                      `posts_comments` t4
                                                    WHERE
                                                      `pid` = t1.`pid` ORDER BY `comment_date` DESC LIMIT 1),'false') AS post_comemnts
                            FROM
                              `users_posts` t1
                            WHERE
                   (`created_date` < '$last_post_date')  AND (`post_status` = '1')  "
                . " AND (`post_max_date` IS NULL OR `post_max_date` > now()) "
                . " AND (`uid` = '$uid'  OR t1.`uid` IN (SELECT `user_1_uid` FROM `users_connections` WHERE `user_2_uid`='$uid' AND `connections_status`=1)) "
                . "ORDER BY `created_date` DESC LIMIT 30;

WHERE (created_date < '$last_post_date') AND (post_status = '1') " . " AND (post_max_date IS NULL OR post_max_date > now()) " . " AND (uid = '$uid' OR t1.uid IN (SELECT user_1_uid FROM users_connections WHERE user_2_uid='$uid' AND connections_status=1)) " . "ORDER BY created_date DESC LIMIT 30;

im trying to run the above query but the result is wrong ,, i suppose some conditions are failing , the problem from the "OR" statement it overriding the "AND" conditions ? , what i can do to solve this issue ?

Upvotes: 0

Views: 68

Answers (1)

Saef Myth
Saef Myth

Reputation: 297

Sorry my bad ,, i need a smoke ,, i just rearrange the conditions places and there a local conflict in sqlite database

Upvotes: 0

Related Questions