Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / General / Other SQL Server Topics / July 2005

Tip: Looking for answers? Try searching our database.

Problem with JOIN

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RuffAroundTheEdges - 06 Jul 2005 09:38 GMT
I'm learning aspx. I have the following code in my aspx:

SqlConnection connection = new
SqlConnection("server=(local)\\NetSDK;database=pubs;Integrated
Security=SSPI");

String sqlCommand = "SELECT * FROM Titles INNER JOIN MyTable ON
MyTable.title_id=Titles.title_id";

SqlDataAdapter command = new SqlDataAdapter(sqlCommand, connection);
.
.
.
This code returns the correct data set. However, when I use this code:

SqlConnection connection = new
SqlConnection("server=(local)\\NetSDK;database=pubs;Integrated
Security=SSPI");

String sqlCommand = "SELECT Titles.title_id, title, type, pub_id, price,
notes, pubdate FROM Titles INNER JOIN MyTable ON
MyTable.title_id=Titles.title_id";

SqlDataAdapter command = new SqlDataAdapter(sqlCommand, connection);
.
.
.

the returned data set does not contain the MyTable data.
What is Wrong?
Christian Donner - 06 Jul 2005 10:29 GMT
"RuffAroundTheEdges" schrieb:
> I'm learning aspx. I have the following code in my aspx:
>
[quoted text clipped - 21 lines]
> the returned data set does not contain the MyTable data.
> What is Wrong?

You are not asking for data from MyTable. All the fields in the select list
are fields from 'titles', aren't they?
Jens Süßmeyer - 06 Jul 2005 10:37 GMT
If you place the star (*) in the selection list without any prefix for any
table, even all joined tables are used for selecting the columns, If you are
specifying the columns only these are selected.

So in your second example you should go for that statement if you want to
get those columns in addition:

> String sqlCommand = "SELECT Titles.title_id, title, type, pub_id, price,
> notes, pubdate,
myTable.*
FROM Titles INNER JOIN MyTable ON
> MyTable.title_id=Titles.title_id";

HTH, Jens Suessmeyer.

---
http://www.sqlserver2005.de
---

> I'm learning aspx. I have the following code in my aspx:
>
[quoted text clipped - 26 lines]
> the returned data set does not contain the MyTable data.
> What is Wrong?
RuffAroundTheEdges - 07 Jul 2005 01:04 GMT
The example shown in the FROM document page at;
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_pubs
_2v8l.asp


has:

SELECT ProductID, Suppliers.SupplierID
   FROM Suppliers JOIN Products
   ON (Suppliers.SupplierID = Products.SupplierID)
RuffAroundTheEdges - 07 Jul 2005 02:34 GMT
I had to do more reading and found that the SELECT statement works
differently in a JOIN:

SELECT Titles.title.id, ..., MyTable.stuff FROM Titles JOIN MyTable ON
(MyTable.title_id = Titles.title_id)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.