Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 QUERIES - join and multiplication

Author  Topic 

Lanah
Starting Member

1 Post

Posted - 2009-04-24 : 14:42:46
How can I retrieve data from two different tables of a database?
The tables are:
CREATE TABLE Elements(Name TEXT, Symbol TEXT, Mass REAL)
CREATE TABLE Molecules(Name TEXT, Element TEXT, Quantity INTEGER)

I want, for example, to get the Name of the molecule with its molecular mass, which is the sum of its element masses. For example if I hve:
Elements Table: 'Hydrogen', 'H', 1.009
Molecules Table: 'Methane', 'Hydrogen', 4

Would get [('Methane', 4.036)]

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-04-24 : 14:47:01
[code]select
Molecules.Name ,
weight=Molecules.Quantity * Elements.Mass
from
Molecules
join Elements on Molecules.Element =Elements.Name [/code]
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-04-24 : 14:49:25
Also, Why are you using text data type. Might as well have varchar for this. And, Isn't the at. weight of Hydrogen 1.00794 instead ?
Go to Top of Page
   

- Advertisement -