Jump to content

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


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

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.