Q:

How can I tell whether a package was installed by dpkg or apt? 

I want to remove the package, but I forgot how I installed it through dpkg or apt-get
I try to check through dpkg-query -list | grep myPackage and apt list --installed | grep myPackage, but myPackage was shown on both. 
so how can I tell whether the package was installed by dpkg or apt ? 
In order to do the correct uninstall command, like: apt-get remove or dpkg -r

A:

Compare the log of /var/log/apt/term.log, which is the log file generated by apt and /var/log/dpkg.log, which is the log file generated by dpkg.  If you note a package name which can be found in /var/log/dpkg.log but not in /var/log/apt/term.log, it is very likely that you installed the package by dpkg that time. 
Please remember apt is a frontend for dpkg.  Thus, it is recommended to remove any package by apt rather than dpkg, because apt will handle the dependency to remove those packages which will not be used by any other packages (, or mark them as "not use anymore" to let you remove them later.  It depends on the exact apt options you actually use).  However, it is no harm to you to remove your package by dpkg if you want.  You will just likely leave many packages that you won't use anymore. 

A:

Any package installed with APT is also installed with dpkg.  APT calculates dependencies and fetches the packages, which are then unpacked and installed by dpkg. 
If you can find your packages with APT, then you should use apt commands to uninstall them, because APT will calculate dependencies of the package and:

remove packages that depend on the package selected for removal
mark packages that are dependencies of the package selected for removal as no longer needed, so that they can be cleaned up with sudo apt autoremove

A:

It does not matter how to uninstall a package. 
dpkg also requires dependencies that are set in the package. 
When you run apt remove it starts dpkg to remove the package. 
When you install a package using dpkg and it requires some dependenices, the installation process stops with an error.  You can fix it by sudo apt install -f that will install dependencies if they are available.  In this case apt autoremove will work the same way.