sql 高级使用 join

菜鸟写法:



SELECT  * from Groups  WHERE `Name` = 'tyj天赢居' 

SELECT  * from GroupEasemob WHERE `groupId` = 72


大神写法:

SELECT  * from Groups left join GroupEasemob on Groups.groupId = GroupEasemob.groupId WHERE `Name` = 'tyj天赢居'  


SELECT * FROM User where UserName =  'CM-8117622'

SELECT  * from Groups left join GroupEasemob on Groups.groupId = GroupEasemob.groupId WHERE `Name`  LIKE '%猎枪'  
select * from GroupUserRelation where userid=8117622 and groupid=117 and expiredTime>now()
SELECT
    easemobId
FROM
    GroupUserRelation
WHERE
    userid =(
        SELECT
            userid
        FROM
            User
        WHERE
            UserName = 'CM-8008316'
    )
AND groupid =(
    SELECT
        Groups.GroupId
    FROM
        Groups
    LEFT JOIN GroupEasemob ON Groups.groupId = GroupEasemob.groupId
    WHERE
        `Name` = '木头玩股'
    LIMIT 1
)
AND expiredTime > now()

你可能感兴趣的:(sql 高级使用 join)