SQL query multiple tables

后端 未结 6 1147
予麋鹿
予麋鹿 2021-01-24 22:41

I have 2 tables and I need to select the relative information, need some help with the query.

Table 2 has ID, MaskID columns.

相关标签:
6条回答
  • 2021-01-24 23:20

    The TSQL query would be:

    SELECT t2.ID, t3.MaskName, t3.Total
    FROM Table2 AS t2 INNER JOIN Table3 AS t3 ON (t2.MaskId = t3.MaskId)
    WHERE ID = 123
    

    Unsure what you mean by 'traverse' through them.

    0 讨论(0)
  • 2021-01-24 23:20
    select ID, MaskName, Total from TABLE_2
    inner join TABLE_3 on (TABLE_2.MaskID=TABLE_3.MaskID)
    where ID=111
    
    0 讨论(0)
  • 2021-01-24 23:25

    You may want to use a Join in your sql query. The w3schools site has a page explaining how to use it.

    0 讨论(0)
  • 2021-01-24 23:32
    SELECT t2.ID,t3.MaskName,t3.Total
    FROM Table2  t2 INNER JOIN  Table3 t3
    ON t2.MaskID=t3.MaskID;
    
    0 讨论(0)
  • 2021-01-24 23:34

    you shoud use this query

    select ID,MaskName,Total from Table1 Inner join Table2 on Table1.MaskID = Table2.MaskId where ID = "given value"

    0 讨论(0)
  • 2021-01-24 23:40
    SELECT a.ID, b.MaskName, b.Total from 2 a INNER JOIN 3  b ON a.MaskID=b.MaskID WHERE ID='Given value'
    

    This is a simple MySQl/T SQL/ PLSQL query. Just use an INNER JOIN on the two tables. A Join works by combining the two tables side by side. The INNER JOIN only outputs the result of the intersection of the two tables. That is, only those rows where the primary key and foreign key have a matching value.

    In certain cases, you may want other rows outputted as well, for such cases look up LEFT JOIN, RIGHT JOIN and FULL JOIN.

    0 讨论(0)
提交回复
热议问题