SQL Join Query - PHP echo data values

Hi,

We've had some SQL code written:

SELECT * FROM eventTasks AS A left join eventTasksActioned AS B on A.id = B.eventTaskId WHERE (B.id is null || B.status != 3)

which joins two tables `eventTasks` and  `eventTasksActioned`

Problem is they share 2 of the same fields (id and eventId), when we try to echo them out we get the wrong one, we want to obtain the other one.

Data comes from eventTasksActioned, but we require them from eventTasks.

Any ideas?
Thanks!!
dev09Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
Instead of SELECT *, if you want the id FROM A, then list all fields in A, but use B.* to get all the fields from B


SELECT A.id, A.eventid, B.* FROM eventTasks AS A left join eventTasksActioned AS B on A.id = B.eventTaskId WHERE (B.id is null || B.status != 3)

Open in new window

Julian HansenCommented:
There are a couple of ways to do this
A. Simply include the fields in the SELECT that you want

SELET A.id, A.eventid, B.somefield, B.someother_field FROM ....

Open in new window


Or you can alias the fields - explicitly include them in the SELECT but use the AS keyword to give them different names. When you run the query you can access the values by the new names.
SELECT A.id AS EventTasksID, A.eventid AS EventTasksEventId, B.* 
FROM eventTasks AS A left join eventTasksActioned AS B on A.id = B.eventTaskId 
WHERE (B.id is null || B.status != 3)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dev09Author Commented:
Perfect! Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.