简体   繁体   中英

Selecting data from table with join

I have two tables and I am trying to get information with an outer left join.

I have the following query:

SELECT * 
  FROM sportjefit_user 
  LEFT OUTER JOIN vriend ON sportjefit_user.id = vriend.vriend2

and this result: 在此处输入图片说明

I only want the records where 'vriend1' or 'vriend2' is not 48

Can somebody please help me out?

Thanks.

SELECT * FROM sportjefit_user 
LEFT OUTER JOIN vriend ON sportjefit_user.id = vriend.vriend2
WHERE vriend1 <> 48
OR vriend2 <> 48

Or if you wanted to ensure that neither field was 48

SELECT * FROM sportjefit_user 
LEFT OUTER JOIN vriend ON sportjefit_user.id = vriend.vriend2
WHERE vriend1 <> 48
AND vriend2 <> 48

add a where clause which would map almost exactly to what you stated that you need:

SELECT * 
FROM sportjefit_user LEFT OUTER JOIN vriend ON sportjefit_user.id=vriend.vriend2
  where !(vriend1=48 or vriend2=48) 
  or (vfriend1 is null and vfriend2 is null);

Try this:

SELECT * FROM sportjefit_user 
LEFT OUTER JOIN vriend 
ON sportjefit_user.id = vriend.vriend2
WHERE ((vriend.vriend1<>48) AND (vriend.vriend2<>48))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM