Answer the question
In order to leave comments, you need to log in
Am I doing the INNER JOIN correctly?
Good morning.
There are tables in the database (an example of an entry in brackets):
premissions : id name //(1,"page_edit")
group_premissions: id group_id premission_id //(1,1)
user_groups: id group_name //(1,"Редакторы")
users: id group_id //(1,1)
SELECT
premissions.name,
group_premissions.group_id,
group_premissions.premission_id,
users.id as userid,
user_groups.group_name
from group_premissions
inner join premissions on group_premissions.premission_id=premissions.id
inner join user_groups on user_groups.id=group_premissions.group_id
inner JOIN users on users.group_id=user_groups.id
WHERE users.id='1'
SELECT A.value1, A.value2, B.value1, B.value2 FROM A,B where A.value1=1 AND A.value2=B.value1
Answer the question
In order to leave comments, you need to log in
It's actually easier than it looks.
An inner join is the most common table join. It is not even necessary to indicate that this is an inner join, if there is a simpler syntax, it will still be an inner join.
An inner join means that as a result you will get what was in both tables at once. If at least one of the tables did not have a record matching the join condition, you will not get the corresponding row.
An outer join means that in addition to what an inner join would give you, you will additionally receive data from the first (left join) or second (right join) table. Even if there were no records in the other table that matched the join condition.
Why would you need an outer join? For example, you have users who are not members of any group. By building an outer left join on the users table and on the groups table, you will get a complete list of users. Those of them that are not included in any group will also be present in the list, but NULL will be indicated in the columns describing the groups.
If you build exactly the same query on an internal (normal) connection, that is, connect users and groups, you will get only those who are part of at least some group.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question