Mickey Mickey - 20 days ago 5
PHP Question

SQL id selection on join tables

I'm accessing the id from my second table ,but i need to access the id from the first one.The tables have the same id's.
Here is my code:

SELECT * FROM workers_requestes_packages a
INNER JOIN packages b
ON a.package_user = b.id
WHERE b.isPaid = 'Y'AND isDelivered='Y' AND isDownloaded='Y'


When i run the query i get an output as below:
enter image description here

I'd like to access the first id(from value 116 and not the 129 value)

Answer

I'd avoid using SELECT * for a start. Just include the columns you actually need - there's all kinds of sensible reasons why you should do this.

Prefix the column name you want with its alias (e.g. a.id), as below.

SELECT a.id FROM workers_requestes_packages a
          INNER JOIN packages b
          ON a.package_user = b.id
          WHERE b.isPaid = 'Y'AND isDelivered='Y' AND isDownloaded='Y'