منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : inner join اكتر من جدول
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
عندي جدول gov اب - جدول Items  اب   - - جدول store  ابن  gov  و   items
items = Item_ID       Item_Name
office = Office_Code   Office_Name
 store =  Store_ID   Store_Office_ID   Store_Item_ID  Store_Item_status     Store_Item_Quentety   Store_Item_Type
الشكله في جملة السلكت

لما عملت inner join بين جدول ال store  وجدول ال items الدنيا اشتغلت تمام
ولما عملتها بين ال store  و office اشتغلت تمام

لما عملت جملة السلكت بالاتنين بيطلع ايرور

الكود كالتالي:-

1- كود بين store  وبين items :-
PHP كود :
Dim SLCTStr3 As String "select items.item_name , store_office_id , store.store_item_quentety , store.store_item_type from store " _
                                 
"inner join items on store.store_item_id = items.item_id" 

2- بين store  وبين office

PHP كود :
Dim SLCTStr6 As String "select office.office_name , store.store_item_quentety , store.store_item_type from store " _
                                 
"inner join office on store.store_office_id = office.office_code" 

3- الثلاث جداول : -

PHP كود :
Dim SLCTStr4 As String "select items.item_name , office.office_name , store.store_item_quentety , store.store_item_type from store " _
                                 
" inner join items   on store.store_item_id = items.item_id " _
                                 
" inner join office on store.Store_Office_ID = office.Office_Code" 

رساله الخطاء :-
Syntax error (missing operator) in query expression 'store.store_item_id = items.item_id  inner join office on store.Store_Office_ID = office.Office_Cod'.

اشتغلت بالسيلكت دي:- بس لو حد عنده اضافه يقولي او حاجه افضل

PHP كود :
Dim SLCTStr4 As String "select items.item_name , office.office_name , store.store_item_quentety , store.store_item_type from (store " _
                                 
" inner join items   on store.store_item_id = items.item_id )" _
                                 
" inner join office on store.Store_Office_ID = office.Office_Code" 

باضافة الاقواس بعد from  بس لو هنحتاج 4 جداول او اكتر نعمل ايه؟
الصحيح تكون هكذا
PHP كود :
SELECT
  items
.item_name,
  
office.office_name,
  
store.store_item_quentety,
  
store.store_item_type
FROM items
INNER JOIN store
  ON store
.store_item_id items.item_id
INNER JOIN office
  ON store
.Store_Office_ID office.Office_Code 

حتقول ايش السبب!

السبب ان كل INNER JOIN ترتبط باللي قبله مباشرة،
يعني المفروض هنا يكون الstore مربوط بالitems والoffice مربوط بالstore، ما ادري وضحت الفكرة.