although, this is not an asp.net problem but i really need your help!
For example, i had 3 tables (TableA, TableB, TableC)
(Relationship example)
(TableA) (TableB) (TableC)
ID 1--- 1 --1
TableAID ---ID -
TableCID ID----
if i have a relationship same as the above, but the TableB only contain the value for TableA but no TableC. how can i generate out the data for TableB if a data is missing in one field.
(Sql statement) 'This is my sql statement that cannot output anydata from TableB
select * from TableB where
TableA.ID = TableB.TableAID And
TableC.ID = TableB.TableCID
Thanks everyoneYou need to create an inner join.
Are you using SQL Server?
If so you can do this graphically by creating a new view. Then add the tables you want to use and then select the columns you want to pull data from. Sql then generates the syntax for you.
You have to relate your tables. Each must carry a PrimaryKey and a Foreign key that relates to the PrimaryKey on the other table. eg
Table1
PK_Tbl1
FK_Tbl2_ID
Table2
PK_Tbl2_ID
FK_Tbl3_ID
Table3
PK_Tbl3_ID
An inner join is much more efficient than a cross join.|||I'm struggling to undestand the question, but given...
>> if i have a relationship same as the above, but the TableB only contain the value for TableA but no TableC. how can i generate out the data for TableB if a data is missing in one field
...sounds like you need to look at LEFT joins.|||thanks for the reply!!!
actually, my project has multiple tables need to be join like this with relationship missing in tables....i am also wondering how to use left or outer join to join multi tables.
thanks|||Reading midi25s reply has made me wonder, do you actually need to have this "missing data"? Are the tables there already and you're working with them or are you also trying to create a data schema?|||i am generating reports from those tables...the report that i am dealing with now is approximately 7 tables, some of the table has missing data and need to be present in the report.
OK for example. i make a sale, but the customer did not put in the shipping address...therefore the shipping address id is missing from the sales table. but in my case, i had around 7 tables with this kind of senerio...
i think i should use left join to solve this problem but do you have any example using left join to join mulitple tables
thank you for helping and hope you can solve my problem
No comments:
Post a Comment