How to get another table field information

user2574853

I have three tables, user/team/user_team(many-to-many)

user
-----------
id  name 
1   Tom
2   Jerry
3   John

team
------------
id   name
1    t1
2    t2
3    t3

user_team
---------------------
userid   teamid  isdeleted
1        t1       0   <----(0 means not deleted record, which can be searched out)
2        t2       1   <----(1 means deleted record, which can not be searched out)

I want to get all team records information with associated user information like below

--------------
tid tname  username
1   t1     Tom
2   t2     
3   t3

Can you tell me how to write the sql statement?

Sorry for my mistake. I've updated my question by adding one more record t3 in team table.

Ronald Alexander Kailola

try this:

Select a.id as tid
a.name as tname
b.name as username
from team a
LEFT JOIN user_team c on a.name = c.teamid and c.isdeleted = 0
LEFT JOIN user b on b.id = c.userid

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 get the information from table to another page using PHP and MYSQL?

From Dev

How to get information of field on click

From Dev

JSF how to get in validator information if field is required?

From Dev

How to get count of two fields from two different table with grouping a field from another table in mysql

From Dev

How to get count of two fields from two different table with grouping a field from another table in mysql

From Dev

Get information from another table using intermediate table

From Dev

how to set one field in a table equal to another field in a table in access

From Dev

MS Access ?: How to pull information into a table from another linked table

From Dev

how can I get faster FTS4 query results ordered by a field in another table?

From Dev

How to get nth field of each create table refering to another file under linux shell?

From Dev

How to get nth field of each create table refering to another file under linux shell?

From Dev

How to get the directory information in the workspace of Light Table?

From Dev

How to get information from SQL table with php

From Dev

how to get count of another table

From Dev

How to create new field in view with some offset (field of table) from existing field (another field of table)?

From Dev

How to add another string with another string in an existing string table field

From Dev

MySQL how to UPDATE a field in one table based on values in another table

From Dev

SQL: how to select something using information from another table

From Dev

How get custom field in aspnetusers table?

From Dev

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

From Dev

How to get total occurrence of element in a list and create another list with this information:

From Dev

Get data from a table based on a table name as a field value from another table

From Dev

How to get referenced values from another table?

From Dev

how to get output by part of data in another table

From Dev

How to get password from another table?

From Dev

How to migrate data from a field to another in a table using south

From Dev

Cakephp how to create virtual field based off another table

From Dev

How to select field in another table join by eager loading in Laravel

From Dev

How to join a table with two tables by choosing another field value

Related Related

  1. 1

    How to get the information from table to another page using PHP and MYSQL?

  2. 2

    How to get information of field on click

  3. 3

    JSF how to get in validator information if field is required?

  4. 4

    How to get count of two fields from two different table with grouping a field from another table in mysql

  5. 5

    How to get count of two fields from two different table with grouping a field from another table in mysql

  6. 6

    Get information from another table using intermediate table

  7. 7

    how to set one field in a table equal to another field in a table in access

  8. 8

    MS Access ?: How to pull information into a table from another linked table

  9. 9

    how can I get faster FTS4 query results ordered by a field in another table?

  10. 10

    How to get nth field of each create table refering to another file under linux shell?

  11. 11

    How to get nth field of each create table refering to another file under linux shell?

  12. 12

    How to get the directory information in the workspace of Light Table?

  13. 13

    How to get information from SQL table with php

  14. 14

    how to get count of another table

  15. 15

    How to create new field in view with some offset (field of table) from existing field (another field of table)?

  16. 16

    How to add another string with another string in an existing string table field

  17. 17

    MySQL how to UPDATE a field in one table based on values in another table

  18. 18

    SQL: how to select something using information from another table

  19. 19

    How get custom field in aspnetusers table?

  20. 20

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

  21. 21

    How to get total occurrence of element in a list and create another list with this information:

  22. 22

    Get data from a table based on a table name as a field value from another table

  23. 23

    How to get referenced values from another table?

  24. 24

    how to get output by part of data in another table

  25. 25

    How to get password from another table?

  26. 26

    How to migrate data from a field to another in a table using south

  27. 27

    Cakephp how to create virtual field based off another table

  28. 28

    How to select field in another table join by eager loading in Laravel

  29. 29

    How to join a table with two tables by choosing another field value

HotTag

Archive