Jump to content

Recommended Posts

Hey,

 

I have a query with two inner joins or trying to anyway - but its not returning the rows correctly when it should find at least 1 row based on current data in my database.... this is what i tried:

 

<?php
$Get = mysql_query("
SELECT (army.Quantity+times.Quantity) AS TotalQuantity,military.Size 
  FROM army
INNER JOIN military ON army.ID=military.ID
INNER JOIN times ON army.ID=times.ID
	WHERE (times.UserID='$UserID' AND times.Type='Buy' AND times.Quantity>0)
		OR (army.Quantity > 0 AND army.UserID='$UserID')")
Or die(mysql_error());
?>

 

Currently army is empty, but times has 1 row with matching UserID and with a quantity of 500 and type set to "Buy" but mysql_num_rows returns 0. The idea is to get the total quantity the user has of a army ID which could be on either of the two: army or times table.

 

Hope you can help.

Link to comment
https://forums.phpfreaks.com/topic/188153-double-inner-join-not-returning-rows/
Share on other sites

I believe that an INNER JOIN will only return data if a row is found in both tables, if army is empty then you do not wish an INNER JOIN. To return results where one or more of the tables have a row I believe you should use FULL JOIN.

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.