1

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

Table 2 has ID, MaskID columns.

Table 3 has MaskID, MaskName, Total

Assuming that I have an ID already given, how can I select the ID, MaskName, Total from the tables? How do I traverse though them?

0

6 Answers 6

2
SELECT t2.ID,t3.MaskName,t3.Total
FROM Table2  t2 INNER JOIN  Table3 t3
ON t2.MaskID=t3.MaskID;
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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

1 Comment

it is a bad thing to mention w3schools as a resource on SO (see w3fools.com). There are much better resources out there including codinghorror.com/blog/2007/10/…
0
select ID, MaskName, Total from TABLE_2
inner join TABLE_3 on (TABLE_2.MaskID=TABLE_3.MaskID)
where ID=111

Comments

0
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.

Comments

-1

you shoud use this query

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

1 Comment

You should use the proper ANSI style JOIN syntax - don't just list tables in a comma-separated list - use the INNER JOIN syntax! It's the ANSI standard, it's much clearer to the reader!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.