Jump to content

LEFT JOINS and regular joins


gterre

Recommended Posts

[quote author=gterre link=topic=108352.msg435841#msg435841 date=1158454873]
I'm trying to do a select query with a left join and regular join and keep getting a mysql error. Is this even possible?
[/quote]
It's possible. Although, the results may not be what you expect. Post the query and the error.
Link to comment
Share on other sites

$result = @mysql_query('SELECT TT_number, datetimeend, service, MINUTE(datetimestart) AS startminute, HOUR(datetimestart) AS starthour, DAYOFMONTH(datetimestart) AS startday, MONTH(datetimestart) AS startmonth, YEAR(datetimestart) AS startyear, category, status, priority.order, priority, description, datetimestart FROM troubleticket, priority, category, services WHERE TT_number="'.$tt.'" LEFT JOIN troubleticket ON lawid=law.lawid AND troubleticket.pid=priority.pid AND troubleticket.catid=category.catid AND services.sid=troubleticket.sid ');

$row = mysql_fetch_array($result);


error is:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\NetTicket\editticket.php on line 16


I want to join my law table to my troubleticket table, my trouble ticket table is the main table.
Link to comment
Share on other sites

Change the mysql_query call to the following and post the query and error shown.

[code=php:0]
$query = 'SELECT TT_number, datetimeend, service, MINUTE(datetimestart) AS startminute, HOUR(datetimestart) AS starthour, DAYOFMONTH(datetimestart) AS startday, MONTH(datetimestart) AS startmonth, YEAR(datetimestart) AS startyear, category, status, priority.order, priority, description, datetimestart FROM troubleticket, priority, category, services WHERE TT_number="'.$tt.'" LEFT JOIN troubleticket ON lawid=law.lawid AND troubleticket.pid=priority.pid AND troubleticket.catid=category.catid AND services.sid=troubleticket.sid ';
$result = mysql_query($query) or die($query."<br />\n".mysql_error());
[/code]
Link to comment
Share on other sites

Using the following syntax to do the joins should make things clearer.
[code]
SELECT
col1, col2 ...
FROM
table1
INNER JOIN
table2
ON
table1.col = table2.col
INNER JOIN
table3
ON
table2.col = table3.col
LEFT JOIN
table4
ON table3.col = table4.col
...
...
WHERE
...
[/code]

If you're still having trouble post the query you're currently using in addition to the error shown when you use the method shown in the earlier post to make the mysql_query call.
Link to comment
Share on other sites

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.