troubleshooting Question

MySQL - exclude certain records from results

Avatar of sabecs
sabecs asked on
MySQL Server
4 Comments1 Solution445 ViewsLast Modified:
Is it possible to modify my SQL statement below to exclude users from results if they match records found in my blocked user table?

For example if my id is 17, I dont want my details appearing if id's of 666 or 456 are performing the search?

$my_id = "17";
$their_id = "666";

u.sess_id AS sess_id,
u.username AS username,  
u.session_last_active AS last_active, AS email, AS contact,
u.member_type AS member_type,
hobbies.updated AS hobbies_upd,
matchi.updated AS match_upd,
profile.countryLive AS country,
photos.image1 AS image1,
photos.updated AS photos_upd,
video.updated AS video_upd
FROM users AS u
INNER JOIN user_upd_hobbies_interest AS hobbies,
user_upd_match_info AS matchi,
user_upd_personality AS personality,
user_upd_my_profile AS profile,
user_upd_photos AS photos,
user_upd_video AS video
id = hobbies.user_id
AND id = matchi.user_id
AND id = personality.user_id
AND id = profile.user_id
AND id = photos.user_id
AND id = video.user_id
AND profile.updated = '1'
ORDER BY member_type DESC, photos_upd DES

  `id` int(11) NOT NULL auto_increment,
  `toid` int(11) NOT NULL,
  `fromid` int(11) NOT NULL,
  UNIQUE KEY `id` (`id`),
  KEY `toid` (`toid`),
  KEY `fromid` (`fromid`)

-- Dumping data for table `block_user`

INSERT INTO `block_user` (`id`, `toid`, `fromid`) VALUES
(22, 29, 567),
(23, 666, 17),
(24, 456, 17);
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros