Home News Contact Us Forum About Us Demos Products F.A.Q.
Shopping Cart
You currently have 0 items in your cart.


Recent Events
  • 23/11/2024 Black Friday 2024

    BIG SALE, 30% discount for all our extensions. Use BF24 coupon code. Hurry up the discount is valid till 3 December.

  • 31/12/2023 New Year SALE

    We are glad to announce New Year SALE. 25% discount for all our extensions. Use NY24 coupon code. Hurry up the discount is valid till 7 January.


2Checkout.com, Inc. is an authorized retailer of goods and services provided by ARI Soft. 2CheckOut




Follow us on twitter



Welcome, Guest
Please Login or Register.    Lost Password?

Joining two different tables
(1 viewing) (1) Guest
Go to bottomPage: 12
TOPIC: Joining two different tables
#39536
Joining two different tables 11 Years, 7 Months ago Karma: 0
Hi!
I'm trying to pull a report that has to pull information from 2 tables in the same database- and then be able to enter date range to filter table. From other posts I was trying this but can't get it to work. My user_id is my link between tables.

SELECT
jml_comprofiler.firstname, jml_comprofiler.lastname,
jml_comprofiler.user_id,
jml_cbsubs_subscriptions.expiry_date,
jml_cbsubs_subscriptions.user_id,
FROM
jml_comprofiler.user_id INNER JOIN jml_cbsubs_subscriptions.user_id
ON jml_cbsubs_subscriptions.user_id = jml_cbsubs_subscriptions.user_id
WHERE
({$REQUEST:start|empty:''} = '' OR jml_cbsubs_subscriptions.expiry_date >= {$REQUEST:start|empty:''})
AND
({$REQUEST:End|empty:''} = '' OR jml_cbsubs_subscriptions.expiry_date < {$REQUEST:End|empty:''})

Thanks for any help,
Tasha
The administrator has disabled public write access.
 
#39560
Re:Joining two different tables 11 Years, 7 Months ago Karma: 760
Hello,

Try the following SQL query:

SELECT
C.firstname,
C.lastname,
C.user_id,
S.expiry_date,
S.user_id
FROM
jml_comprofiler C INNER JOIN jml_cbsubs_subscriptions S
ON C.user_id = S.user_id
WHERE
({$REQUEST:start|empty:''} = '' OR S.expiry_date >= {$REQUEST:start|empty:''})
AND
({$REQUEST:End|empty:''} = '' OR S.expiry_date < {$REQUEST:End|empty:''})

Regards,
ARI Soft
The administrator has disabled public write access.
 
#39562
Re:Joining two different tables 11 Years, 7 Months ago Karma: 0
Thank you! Thank you! Thank you!
If I could leave another review on how awesome ARI data and their support is in Joomla! extensions I would! Thanks, Tasha
The administrator has disabled public write access.
 
#40160
Re:Joining two different tables 11 Years, 7 Months ago Karma: 0
I would like to add a third table to my query now
I tired the inner join but I get an inner join error on line 14 (which is the P.id line).
Any ideas?

SELECT
C.cb_businessname,
C.firstname,
C.lastname,
C.cb_subs_inv_address_street,
C.cb_subs_inv_address_city,
C.cb_subs_inv_address_state,
C.cb_subs_inv_address_zip,
C.cb_phone,
C.user_id,
S.expiry_date,
S.plan_id,
S.user_id
P.id
FROM
jml_comprofiler C INNER JOIN jml_cbsubs_subscriptions S
ON C.user_id = S.user_id
INNER JOIN jml_cbsubs_subscriptions S
ON P.id = S.plan_id
WHERE
({$REQUEST:start|empty:''} = '' OR S.expiry_date >= {$REQUEST:start|empty:''})
AND
({$REQUEST:End|empty:''} = '' OR S.expiry_date < {$REQUEST:End|empty:''})
The administrator has disabled public write access.
 
#40162
Re:Joining two different tables 11 Years, 7 Months ago Karma: 760
Try the following query:

Code:


SELECT
  C.cb_businessname,
  C.firstname,
  C.lastname,
  C.cb_subs_inv_address_street,
  C.cb_subs_inv_address_city,
  C.cb_subs_inv_address_state,
  C.cb_subs_inv_address_zip,
  C.cb_phone,
  C.user_id,
  S.expiry_date,
  S.plan_id,
  S.user_id,
  P.id
FROM
  jml_comprofiler C INNER JOIN jml_cbsubs_subscriptions S
    ON C.user_id = S.user_id
  INNER JOIN jml_cbsubs_subscriptions S
    ON P.id = S.plan_id
WHERE
  ({$REQUEST:start|empty:''} = '' OR S.expiry_date >= {$REQUEST:start|empty:''})
  AND
  ({$REQUEST:End|empty:''} = '' OR S.expiry_date < {$REQUEST:End|empty:''}) 



Regards,
ARI Soft
The administrator has disabled public write access.
 
#40173
Re:Joining two different tables 11 Years, 7 Months ago Karma: 0
I couldn't get that to work. I think that I forgot to call the 3rd table which is jml_cbsubs_plans.
So I have
jml_comprofiler = C
jml_cbsubs_subscriptions = S
jml_cbsubs_plans = P

Basically what I'm trying to do is pull user info from comprofiler, subscription information from cbsubs_subscription, and then the cbsubs_subscription had a plan_id that is a number - I need to pull the text wording for cbsubs_plans associated with the plan_id . This way the user sees the wording for the plan, not just a number that makes no sense to them.
Thank you so much for your time and help!
I appreciate it,
Tasha

SELECT
C.cb_businessname,
C.firstname,
C.lastname,
C.cb_subs_inv_address_street,
C.cb_subs_inv_address_city,
C.cb_subs_inv_address_state,
C.cb_subs_inv_address_zip,
C.cb_phone,
C.user_id,
S.expiry_date,
S.plan_id,
S.user_id,
P.id
FROM
jml_comprofiler C INNER JOIN jml_cbsubs_subscriptions S
ON C.user_id = S.user_id
jml_cbsubs_plans P INNER JOIN jml_cbsubs_subscriptions S
ON P.id = S.plan_id
WHERE
({$REQUEST:start|empty:''} = '' OR S.expiry_date >= {$REQUEST:start|empty:''})
AND
({$REQUEST:End|empty:''} = '' OR S.expiry_date < {$REQUEST:End|empty:''})
The administrator has disabled public write access.
 
Go to topPage: 12