Jump to content

[SOLVED] Selecting data from multiple tables whist using CROSS JOIN


matt.sisto

Recommended Posts

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.

  $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.

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."'";

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.