Forums / Code Collaboration / Simple INNER JOIN not returning results

Simple INNER JOIN not returning results

Views: 1,841

Results 1 to 6 of 6
14 Jul 2016, 8:29 PM
#1
jeffiec avatar

jeffiec

New Zenner

Join Date:
Jun 2009
Posts:
86
Plugin Contributions:
0

Simple INNER JOIN not returning results

So i have product type forklift, when adding a new product, adds a ton of extra fields to a table using products_id = forklift_id,
I did it a few years ago and its working great, now they are adding a new forklift notification system, (its own little nightmare in another post),
I am setting up listeners that when a new forklift is added, if someone signed up for notifications fitting the specs of the forklift.

I am also setting up a manual notification system and on page load, i want to see which forklifts have been added.

$sel_forklifts = "select pf.forklift_id, pf.forklift_cpac, pf.forklift_fuel, pf.forklift_tires, pf.forklift_make, pd.products_id from "
		.TABLE_FORKLIFT. " pf" .
		" INNER JOIN " .TABLE_PRODUCTS. " pd".
		" ON pf.forklift_id = pd.products_id ".		
		" where pd.products_date_added between '".$tdate."' and '".$edit_time."'";

Even pasting into the mysql backend:
SELECT pf.forklift_id, pf.forklift_cpac, pf.forklift_fuel, pf.forklift_tires, pf.forklift_make, pd.products_id
FROM zen_forklift pf
INNER JOIN zen_products pd ON pf.forklift_id = pd.products_id
WHERE pd.products_date_added
BETWEEN '2016-07-04'
AND '2016-07-14'
LIMIT 0 , 30

No results

Seems to not return any hits, even though i know there are at least 6 that should come up.
Can anyone give me a little guidance, im not the best with joins.
Thanks a ton.
Jeff

14 Jul 2016, 11:37 PM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Simple INNER JOIN not returning results

Thinking that because the dates are actual date fields, that need to address them similar to the following:

SELECT pf.forklift_id, pf.forklift_cpac, pf.forklift_fuel, pf.forklift_tires, pf.forklift_make, pd.products_id
FROM zen_forklift pf
INNER JOIN zen_products pd ON pf.forklift_id = pd.products_id
WHERE pd.products_date_added
BETWEEN CAST('2016-07-04' AS DATE)
AND CAST('2016-07-14' AS DATE)
LIMIT 0 , 30;
```

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

15 Jul 2016, 4:42 PM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Simple INNER JOIN not returning results

Ya, I'd test by removing the "where" clause first. If that returns results then you'll know it's date-related.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

15 Jul 2016, 4:57 PM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Simple INNER JOIN not returning results

DrByte:

Ya, I'd test by removing the "where" clause first. If that returns results then you'll know it's date-related.
Thinking a little further on it (and to help with the above test), might want to (temporarily) add the pd.products_date_added field on the return set just so it shows in you results so you can confirm your "suspicion" of having those at least 6 product.

.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

18 Jul 2016, 11:48 AM
#5
jeffiec avatar

jeffiec

New Zenner

Join Date:
Jun 2009
Posts:
86
Plugin Contributions:
0

Re: Simple INNER JOIN not returning results

mc12345678:

Thinking that because the dates are actual date fields, that need to address them similar to the following:

SELECT pf.forklift_id, pf.forklift_cpac, pf.forklift_fuel, pf.forklift_tires, pf.forklift_make, pd.products_id
FROM zen_forklift pf
INNER JOIN zen_products pd ON pf.forklift_id = pd.products_id
WHERE pd.products_date_added
BETWEEN CAST('2016-07-04' AS DATE)
AND CAST('2016-07-14' AS DATE)
LIMIT 0 , 30;


Worked perfectly, thank you!
18 Jul 2016, 2:52 PM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Simple INNER JOIN not returning results

jeffiec:

Worked perfectly, thank you!
Quite welcome! :) good luck!

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...