Jump to content

running multiple queries


searls03

Recommended Posts

hi there.  i am trying to run a query that will select values from two tables.  I would like to run a query to select an event name and an id from table1, and then select subevent from table2 where the event_id is equal to the id from table1 query.  i know how to do this via a couple of loops, but I only want one loop.  can anyone help me get started?  thanks

Link to comment
Share on other sites

It has nothing to do with loops. This can be achieved in a single query.


SELECT a.something, b.somethingelse
FROM table_a a
LEFT JOIN table_b b USING(table_a_id)
If you need more help take a look at some tutorials on using a "MySql JOIN" or post your table structure so we can give you a more concrete example.
Link to comment
Share on other sites

 

It has nothing to do with loops. This can be achieved in a single query.

SELECT a.something, b.somethingelse
FROM table_a a
LEFT JOIN table_b b USING(table_a_id)
If you need more help take a look at some tutorials on using a "MySql JOIN" or post your table structure so we can give you a more concrete example.
Link to comment
Share on other sites

You want to run ONE query. Not two queries. Not multiple queries in loops. One Query.

 

 

SELECT card.event_id, card.qty, card.event,
       events.spots, events.name
FROM card
JOIN events
  ON events.id = card.event_id

 

Did I mention that you only need to run ONE query?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.