At present, this is not so simple due to recent changes in gdal, but also
to changes made to support duplicate layer-names only layerid is being used.
For QGIS compiled against gdal 1.*
should be used and in most cases work correctly.
At the moment an attempt to to open with 'layername' will first be
attempted (without checks for duplicate names, thus the first will be
taken) and if that fails, to open with layerid.
When gdal 2.* is being used, retrieving with layerid will fail after the
first table that has more than 1 geometry.
The goal of the Grant Programme '9) Correction of QgsOgrProvider
implementaion of GDAL 2.0' was to resolve this problem.
Qgis-developer mailing list
List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer