Link to home
Start Free TrialLog in
Avatar of lxfdirs
lxfdirs

asked on

Including items from various tables in a query MySQL.

Hi,

I need to generate a MySQL query based on a field from a table. My database contains 2 tables. On each record found by the query  I need to include data from the other table. This other data should be linked based on a specific field on the record found by the main query.
Hope I have explained myself.

Regards
Avatar of Ara-
Ara-
Flag of Norway image

Your question is kinda vague, but you can do a new SELECT in the WHERE-clause.

E.g.:
SELECT name FROM table1 WHERE id=(SELECT id FROM table2 WHERE field=3)
ASKER CERTIFIED SOLUTION
Avatar of Cornelia Yoder
Cornelia Yoder
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of theGhost_k8
theGhost_k8
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jeff_01
jeff_01

Perhaps you could provide a bit more info and some sample data but I think you are trying to do this below ?


select * from tableA, tableB where tableA.ID = tableB.ID

Don't use JOIN unless you absolutely have to, it's much messier and complicated to understand and debug.
            Hi!

To speed up the query make sure that you have indexes on both tables
that matches the columns you use in the where clauses of the query . :)

Regards,
    Tomas Helgi
Avatar of lxfdirs

ASKER

Guys:

Thank you all for the suggestions.
I will be checking on them and come back to you with the accepted solution.

Regards
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.