How to select/match from MySQL table?

JosephGarrone

I have the following table:

People
---------
ID | Name
---------
 1 | John
 2 | Sam

And I have another table:

Permissions
-----------
ID | Perm
-----------
 1 | View
 2 | Edit
 3 | Delete

These two tables are linked in a third table:

UserPermissions
----------------------
ID | User | Permission
----------------------
 1 |   1  |  1 (View)
 2 |   1  |  3 (Delete)
 3 |   2  |  1 (View)

I am trying to select a "total" permissions type table, where, if I wanted to get the permission for a user (Lets say user 2 (Sam)), I would get the following table:

UserPermissions
------------------
Permission | User
------------------
 1 (View)  |  2
 2 (Edit)  | NULL (Or some other nullish value)
 3 (Delete)| NULL

I have only recently started MySQL and I have no idea of what search terms I should be trying to get examples of similar queries. Does anyone know what type of queries I should be searching for / a way to implement this?

Gordon Linoff

If you want to do this for one user, you want a left outer join:

select p.*, up.user;
from Permissions p left outer join
     UserPermissions up
     on p.Permission = up.Permission and
        up.User = 2;

This works for one user.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to rotate a table from MySql

From Dev

How to transfer data from table to table in mysql

From Dev

How to get just the fields from a table in MySQL?

From Java

How to remove constraints from my MySQL table?

From Dev

how to delete a single value from mysql table

From Dev

How to hide column from user in MySQL table

From Dev

how to get orphans from a join table in mysql

From Dev

How to delete mysql data from table at midnight?

From Dev

How to return table from MySQL function

From Dev

MYSQL - How to UPDATE after SELECT from a table

From Dev

How to update table from query(MYSQL)

From Dev

How to get the minimum id from the table in MySql

From Dev

How to find Average from mysql table in php?

From Dev

MYSQL: How to extract the following data from the table?

From Dev

MySQL - How to recieve table of substrings from string

From Dev

MySQL: How to select distinct values from a table?

From Dev

MYSQL: How to extract the following data from the table?

From Dev

How to get just the fields from a table in MySQL?

From Dev

How to get table name from mysql result?

From Dev

How to delete millions of record from mysql table

From Dev

How to create PHP array from MySQL table

From Dev

How to add comma to a select from mysql table

From Dev

How to Replace and Update Data From One Table to Another Table in MySQL

From Dev

How to add a column to a table from another table in Mysql?

From Dev

How to Get VALUES from another table into another table in PHP/MySQL

From Dev

mysql - how to save results from DESCRIBE table into table

From Dev

How to Replace and Update Data From One Table to Another Table in MySQL

From Dev

How to select data from a table by referring to another table in MySQL

From Dev

How to select from a table based on another table in mysql

Related Related

  1. 1

    How to rotate a table from MySql

  2. 2

    How to transfer data from table to table in mysql

  3. 3

    How to get just the fields from a table in MySQL?

  4. 4

    How to remove constraints from my MySQL table?

  5. 5

    how to delete a single value from mysql table

  6. 6

    How to hide column from user in MySQL table

  7. 7

    how to get orphans from a join table in mysql

  8. 8

    How to delete mysql data from table at midnight?

  9. 9

    How to return table from MySQL function

  10. 10

    MYSQL - How to UPDATE after SELECT from a table

  11. 11

    How to update table from query(MYSQL)

  12. 12

    How to get the minimum id from the table in MySql

  13. 13

    How to find Average from mysql table in php?

  14. 14

    MYSQL: How to extract the following data from the table?

  15. 15

    MySQL - How to recieve table of substrings from string

  16. 16

    MySQL: How to select distinct values from a table?

  17. 17

    MYSQL: How to extract the following data from the table?

  18. 18

    How to get just the fields from a table in MySQL?

  19. 19

    How to get table name from mysql result?

  20. 20

    How to delete millions of record from mysql table

  21. 21

    How to create PHP array from MySQL table

  22. 22

    How to add comma to a select from mysql table

  23. 23

    How to Replace and Update Data From One Table to Another Table in MySQL

  24. 24

    How to add a column to a table from another table in Mysql?

  25. 25

    How to Get VALUES from another table into another table in PHP/MySQL

  26. 26

    mysql - how to save results from DESCRIBE table into table

  27. 27

    How to Replace and Update Data From One Table to Another Table in MySQL

  28. 28

    How to select data from a table by referring to another table in MySQL

  29. 29

    How to select from a table based on another table in mysql

HotTag

Archive