|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
querying multiple tablesI'm wondering if anyone can offer some advice in how to write a query for this type of instance: The data I am looking at is in a table with columns as follows: dbo.data: id, time, value, quality This id value links to another table... dbo.atoms: id, uuid Then this table is linked to the following: dbo.tags: uuid, tagname I want to get the tagname in one query but in the DATA table I only have the ID, not the UUID. I tried the following which produced garbage 'value' data: SELECT time,tagname,value,quality FROM dbo.data,dbo.tags,dbo.atoms WHERE dbo.data.id=dbo.atoms.id AND dbo.atoms.uuid=dbo.tags.uuid Thanks for any advice. Your query looks fine. What does "garbage 'value' data" mean ?
Please provide DDL (including primary keys, foreign keys and unique keys), sample data and expected results. See: http://www.aspfaq.com/etiquette.asp?id=5006 Razvan The query seems to be fine. Can you give some sample data and expected
results and what you get when you run this query. Or can you elucidate on what the garbage 'value' is. From the info you have given, if you didn't join on the primary keys you might have gotten a cross product. But again, thats just a guess. Thanks Razvan and Omnibuzz for your advice...
I got it working... I'm working on a database someone else created and I found another table where I could get the tag names from correctly. It seemed to be related to primary keys, thanks for pointing that out! Malcolm. Show quote "Omnibuzz" wrote: > The query seems to be fine. Can you give some sample data and expected > results and what you get when you run this query. > Or can you elucidate on what the garbage 'value' is. > > From the info you have given, if you didn't join on the primary keys you > might have gotten a cross product. But again, thats just a guess. > > -- > -Omnibuzz (The SQL GC) > > http://omnibuzz-sql.blogspot.com/ > |
|||||||||||||||||||||||