thedepotnetwork Posted February 1, 2010 Share Posted February 1, 2010 I am trying to figure this out, and it is stumping me... even after google searches... I simply want to pull data from two tables, one contains all the data I need, but the VENDOR STATE "vendor_state" is stored as a foreign key so, i simply need to get the state name 2 char "state" from the states table all in one select statement... Here is what i have so far.. SELECT concat( v.vendor_firstname, " ", v.vendor_lastname ) , v.vendor_title, v.vendor_address1, v.vendor_city, s.state, v.vendor_zip, concat( v.vendor_contact_phone1, v.vendor_contact_phone2, v.vendor_contact_phone3 ) , v.vendor_email FROM vendors AS v, states AS s WHERE v.vendor_state =3 This obviously won't work, but just returns the first listed states "ie. AL" when id 3 is Arizona. Quote Link to comment Share on other sites More sharing options...
kickstart Posted February 1, 2010 Share Posted February 1, 2010 Hi What you have there will bring back every possible combination of the rows from the 2 tables where v.vendor_state is 3 (it is a CROSS JOIN, and they can be useful). What you need is something like this SELECT concat( v.vendor_firstname, " ", v.vendor_lastname ) , v.vendor_title, v.vendor_address1, v.vendor_city, s.state, v.vendor_zip, concat( v.vendor_contact_phone1, v.vendor_contact_phone2, v.vendor_contact_phone3 ) , v.vendor_email FROM vendors v INNER JOIN states s ON v.vendor_state = s.vendor_state WHERE v.vendor_state =3 All the best Keith Quote Link to comment Share on other sites More sharing options...
thedepotnetwork Posted February 1, 2010 Author Share Posted February 1, 2010 Better than our inhouse guys. We'll try and get you some donations, thanks! 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.