searls03 Posted March 8, 2013 Share Posted March 8, 2013 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 Quote Link to comment Share on other sites More sharing options...
trq Posted March 8, 2013 Share Posted March 8, 2013 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. Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 8, 2013 Author Share Posted March 8, 2013 ok, so table one is called card. I want to be able to get the event_id from it. I then want to run a query on table "events" where id=the event_id cart. basically that is what it looks like and how I need it to funcion. Quote Link to comment Share on other sites More sharing options...
searls03 Posted March 8, 2013 Author Share Posted March 8, 2013 I gues that isn't all, I also want to then grab all the columns from table one, event_id, qty, event. and then also spots, name from "events" Quote Link to comment Share on other sites More sharing options...
Jessica Posted March 8, 2013 Share Posted March 8, 2013 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. Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 9, 2013 Share Posted March 9, 2013 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.