Multiply joins in vba excel

  • Hello, everyone I have 4 tables

    1/Cars

    CarIdCarBrandIdRegistrationNumberMaxWeight
    133123451
    234123461.1
    333123471.2
    433123481.3
    533123491.4
    636123501.5
    737123511.6
    838123571.7
    934123531.8
    1034123541.9
    1135123552
    1233123562.1

    2/CarBrand

    CarBrandIdCarBrandName
    33Renault
    33Renault
    34Volvo
    35BMW
    36Niva
    37HONDA
    38Lada
    37HONDA
    37HONDA
    39Aston Martin

    3/Drivers

    DriverIDName1
    45Ivanov
    46Petrov
    47Sidorov
    48Ivanov1
    49Petrov1
    50Ivanov
    51Ivanov2
    52Petrov2
    53Ivanov
    54Ivanov3
    55Petrov3
    56Sidorov3

    4/ Carlist

    CarListidCarIdDriverIDCarListDate
    10114521.13.2009 13:13:35
    10224621.13.2008 13:13:36
    10334615.13.2008 13:13:34
    10444516.13.2008 13:13:34
    10554521.13.2008 13:13:36
    10665018.13.2008 13:13:35
    10775121.13.2008 13:13:36
    10885220.13.2008 13:13:36
    10995321.13.2008 13:13:36
    110105322.13.2008 13:13:36
    111115523.13.2008 13:13:37
    112125324.13.2008 13:13:37

    I want to get  CarListid of those drivers whos name1 Ivanov and whos car was for instance VOLVO
    So, I have a query, that works
    'strSQL = "SELECT [Drivers$].DriverID, [CarList$].CarId, [Cars$].CarId, [Cars$].CarBrandId " _
    '& "FROM ([Drivers$]" _
    '& "inner JOIN [CarList$] ON [Drivers$].DriverID = [CarList$].DriverID)" _
    '& "inner JOIN [Cars$] ON [CarList$].CarId = [Cars$].CarId " _
    '& "Where Name1 like 'Petrov%'"

    and that doesnt

    'strSQL = "SELECT [Drivers$].DriverID, [CarList$].CarId, [Cars$].CarBrandId, [CarBrand$].CarBrandId" _
    '& "FROM (([Drivers$]" _
    '& " inner JOIN [CarList$] ON [Drivers$].DriverID = [CarList$].DriverID)" _
    '& " inner JOIN [Cars$] ON [CarList$].CarId = [Cars$].CarId)" _
    '& " inner JOIN [CarsBrand$] ON [Cars$].CarBrandId = [CarsBrand$].CarBrandId " _
    '& " Where Name1 like 'Ivanov%'"

    Could anyone help me to get these carlistid,,,,&

    May be my queries wrong,,,I dont exclude syntax and logical nuances...

  • When you say "it doesn't work", what do you mean? Do you get an error, unexpected results, Excel crashes..? Ideally, if you can, provide your datas DDL and DML statements as well; my signature covers how to do that. What results are you expecting for your queries?

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • everythig is fine 
    i got the solution)!

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply