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.
Author |
Topic |
sureshprabhu
Starting Member
32 Posts |
Posted - 2007-09-27 : 15:38:14
|
Hi!I want to get some fields from more than one table. How can I use select command to do this? Please help me! The results should be in one table only!Thanks in advance! |
|
Kristen
Test
22859 Posts |
Posted - 2007-09-27 : 15:43:13
|
[code]SELECT A.Col1, A.COl2, B.ColX, B.ColYFROM TableA AS A JOIN TableB AS B ON B.SomeColumn = A.SomeOtherColumn[/code]Kristen |
 |
|
sureshprabhu
Starting Member
32 Posts |
Posted - 2007-09-27 : 16:03:08
|
Thanks Kristen for your response, but it is giving one error as "syntax error near '.'" |
 |
|
Zoroaster
Aged Yak Warrior
702 Posts |
Posted - 2007-09-27 : 16:06:11
|
Suresh, post your query please. Future guru in the making. |
 |
|
sureshprabhu
Starting Member
32 Posts |
Posted - 2007-09-27 : 16:14:06
|
select A.id, A.FileData, A.OriginalName, A.ContentType, A.DateCreated, A.Client, A.username B.id, B.FileData, B.OriginalName, B.ContentType, B.DateCreated, B.Client, B.username from Files_Admin as A join Files_Designer AS B on B.id=A.id |
 |
|
Zoroaster
Aged Yak Warrior
702 Posts |
Posted - 2007-09-27 : 16:26:43
|
You left the comma out:quote: Originally posted by sureshprabhu select A.id, A.FileData, A.OriginalName, A.ContentType, A.DateCreated, A.Client, A.username, -- This comma was missing! B.id, B.FileData, B.OriginalName, B.ContentType, B.DateCreated, B.Client, B.username from Files_Admin as A join Files_Designer AS B on B.id=A.id
Future guru in the making. |
 |
|
sureshprabhu
Starting Member
32 Posts |
Posted - 2007-09-27 : 16:36:31
|
Actually i am passing one parameter as OriginalName, it should check in both tables whether it is existing, if existing it should return that particular record. |
 |
|
Zoroaster
Aged Yak Warrior
702 Posts |
Posted - 2007-09-27 : 16:38:19
|
quote: Originally posted by sureshprabhu Actually i am passing one parameter as OriginalName, it should check in both tables whether it is existing, if existing it should return that particular record.
I don't follow your point, the reason you had a syntax error is because the comma was missing. Is the query doing what you want now that you add the comma? Future guru in the making. |
 |
|
sureshprabhu
Starting Member
32 Posts |
Posted - 2007-09-27 : 16:54:49
|
I added comma its working, But now the problem is, I want to retrieve the data from two tables, after matching with my parameter. I am passing this parameter at the time of execution. the parameter is for OriginalName. |
 |
|
Kristen
Test
22859 Posts |
Posted - 2007-09-27 : 19:55:59
|
Not really clear to me what you mean, but perhaps something like:select A.id, A.FileData, A.OriginalName, A.ContentType, A.DateCreated, A.Client, A.username, B.id, B.FileData, B.OriginalName, B.ContentType, B.DateCreated, B.Client, B.username from Files_Admin as A join Files_Designer AS B on B.id=A.idWHERE A.OriginalName = @OriginalName OR B.OriginalName = @OriginalName Kristen |
 |
|
|
|
|
|
|