matt.sisto Posted May 6, 2009 Share Posted May 6, 2009 I have written this sql query with some help and advice: $sql = "SELECT event_id, event_start, event_end, fee FROM calendar_events, first_name AND SELECT last_name FROM client CROSS JOIN client USING (client_id) WHERE calendar_events.event_start >= '".$invoice_start."' AND calendar_events.event_end <= '".$invoice_end."' AND client.org_id = '".$org_id."'"; But I also wish to: SELECT _first_name and last_name FROM client WHERE org_id = '$.org_id'; Can I incorporate this into the same query? I tried and failed. Any help appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/157081-solved-selecting-data-from-multiple-tables-whist-using-cross-join/ Share on other sites More sharing options...
matt.sisto Posted May 6, 2009 Author Share Posted May 6, 2009 $sql = "SELECT event_id, event_start, event_end, fee FROM calendar_events, AND SELECT first_name, last_name FROM client CROSS JOIN client USING (client_id) WHERE calendar_events.event_start >= '".$invoice_start."' AND calendar_events.event_end <= '".$invoice_end."' AND client.org_id = '".$org_id."'"; I tried this but MySQL didn't like it. Quote Link to comment https://forums.phpfreaks.com/topic/157081-solved-selecting-data-from-multiple-tables-whist-using-cross-join/#findComment-827419 Share on other sites More sharing options...
matt.sisto Posted May 6, 2009 Author Share Posted May 6, 2009 I have also tried this but MySQL didn't like it either. $sql = "SELECT calendar_events.event_id, calendar_events.event_start, calendar_events.event_end, calendar_events.fee, client.first_name, client.last_name CROSS JOIN client USING (client_id) WHERE calendar_events.event_start >= '".$invoice_start."' AND calendar_events.event_end <= '".$invoice_end."' AND client.org_id = '".$org_id."'"; Quote Link to comment https://forums.phpfreaks.com/topic/157081-solved-selecting-data-from-multiple-tables-whist-using-cross-join/#findComment-827423 Share on other sites More sharing options...
kickstart Posted May 6, 2009 Share Posted May 6, 2009 Hi You appear to have the column names and the tables that they come from all mixed up. Something like this $sql = "SELECT calendar_events.event_id, calendar_events.event_start, calendar_events.event_end, calendar_events.fee, client.first_name, client.last_name FROM calendar_events CROSS JOIN client USING (client_id) WHERE calendar_events.event_start >= '".$invoice_start."' AND calendar_events.event_end <= '".$invoice_end."' AND client.org_id = '".$org_id."'"; All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/157081-solved-selecting-data-from-multiple-tables-whist-using-cross-join/#findComment-827431 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.