MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 2nd, 2009, 10:55 AM
nimda79 nimda79 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 9 nimda79 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 8 m 55 sec
Reputation Power: 0
Question Having problems converting MS Access Query to mySQL

So I am in the process of moving all my queries from M$ Access to mySQL and having problems with this one...

Code:
SELECT jos_users.name, 
jos_users.username, 
jos_users.email, 
Max(IIf([jos_community_fields_values.field_id]=20,[jos_community_fields_values.value],Null)) AS Company, 
Max(IIf([jos_community_fields_values.field_id]=13,[jos_community_fields_values.value],Null)) AS [Company Website], 
Max(IIf([jos_community_fields_values.field_id]=19,[jos_community_fields_values.value],Null)) AS [Job Title], 
Max(IIf([jos_community_fields_values.field_id]=9,[jos_community_fields_values.value],Null)) AS [Address 1], 
Max(IIf([jos_community_fields_values.field_id]=25,[jos_community_fields_values.value],Null)) AS [Address 2], 
Max(IIf([jos_community_fields_values.field_id]=11,[jos_community_fields_values.value],Null)) AS City, 
Max(IIf([jos_community_fields_values.field_id]=10,[jos_community_fields_values.value],Null)) AS State, 
Max([EMEA by IMT].Country) AS MaxOfCountry, 
Max([EMEA by IMT].IMT) AS MaxOfIMT, 
Max(IIf([jos_community_fields_values.field_id]=26,[jos_community_fields_values.value],Null)) AS Zip, 
jos_users.registerDate, jos_users.lastvisitDate
FROM (jos_users INNER JOIN (jos_community_fields INNER JOIN jos_community_fields_values ON jos_community_fields.id = jos_community_fields_values.field_id) ON jos_users.id = jos_community_fields_values.user_id) LEFT JOIN [EMEA by IMT] ON jos_community_fields_values.value = [EMEA by IMT].Country
GROUP BY jos_users.name, jos_users.username, jos_users.email, jos_users.registerDate, jos_users.lastvisitDate
HAVING (((jos_users.email) Like "*email.com") AND ((Max(IIf([jos_community_fields_values.field_id]=12,[jos_community_fields_values.value]=[EMEA by IMT.Country],Null)))=-1));


So far I have gotten this much converted but still can't get the
(Max(IIf([jos_community_fields_values.field_id]=12,[jos_community_fields_values.value]=[EMEA by IMT.Country],Null)))=-1) part at the end inserted correctly, prehaps I am doing it wrong.

here's what I got so far:
Code:
SET SESSION SQL_BIG_SELECTS=1;
SELECT a.id as `ID`,
a.name as `Name`,
a.username as `Username`,
a.email as `Email`,
MAX(IF(b.field_id=20,b.value, NULL)) AS 'Company',
MAX(IF(b.field_id=13,b.value, NULL)) AS 'Website',
MAX(IF(b.field_id=19,b.value, NULL)) AS 'Job Title',
MAX(IF(b.field_id=9,b.value, NULL)) AS 'Address',
MAX(IF(b.field_id=25,b.value, NULL)) AS 'Address 2',
MAX(IF(b.field_id=11,b.value, NULL)) AS 'City / Town',
MAX(IF(b.field_id=10,b.value, NULL)) AS 'State',
MAX(IF(b.field_id=26,b.value, NULL)) AS 'Zip / Country Code',
c.country AS 'Country',
a.registerDate as `Register`,
a.lastvisitDate as `Last Visit`
FROM jos_users a 
LEFT JOIN jos_community_fields_values b ON a.id = b.user_id
LEFT JOIN jos_emea c ON b.value = c.country
WHERE ((a.email) like "%email.com")
GROUP BY a.id
ORDER BY a.name, a.id


Basically the b.value has tons of data, one of the data values is a Country name picked from a list. That list has been divided into 3 groups based upon geographical location, jos_emea is the list I am currently using. Also e-mail address are separated by this.

When I run the current Query I get everything, but the country fields say NULL except for the ones that are in the list. So I just want to take out the users that have NULL in the country field.

Reply With Quote
  #2  
Old November 2nd, 2009, 11:24 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 20,768 r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 1 Week 3 Days 17 h 39 m 41 sec
Reputation Power: 2481
Code:
SELECT a.id 
     , a.name 
     , a.username 
     , a.email
     , MAX(CASE WHEN b.field_id=20 THEN b.value END) AS 'Company'
     , MAX(CASE WHEN b.field_id=13 THEN b.value END) AS 'Website'
     , MAX(CASE WHEN b.field_id=19 THEN b.value END) AS 'Job Title'
     , MAX(CASE WHEN b.field_id=9  THEN b.value END) AS 'Address'
     , MAX(CASE WHEN b.field_id=25 THEN b.value END) AS 'Address 2'
     , MAX(CASE WHEN b.field_id=11 THEN b.value END) AS 'City / Town'
     , MAX(CASE WHEN b.field_id=10 THEN b.value END) AS 'State'
     , MAX(CASE WHEN b.field_id=26 THEN b.value END) AS 'Zip / Country Code'
     , c.country 
     , a.registerDate AS `Register`
     , a.lastvisitDate AS `Last Visit`
  FROM jos_users a 
LEFT OUTER
  JOIN jos_community_fields_values b 
    ON b.user_id = a.id 
LEFT OUTER
  JOIN jos_emea c 
    ON c.country = b.value
 WHERE a.email LIKE '%email.com'
GROUP 
    BY a.id
ORDER 
    BY a.name
     , a.id
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old November 2nd, 2009, 01:35 PM
nimda79 nimda79 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 9 nimda79 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 8 m 55 sec
Reputation Power: 0
Tried it, still shows all users, instead of the ones who's country belongs in the database jos_emea.

Reply With Quote
  #4  
Old November 2nd, 2009, 01:42 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 20,768 r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 1 Week 3 Days 17 h 39 m 41 sec
Reputation Power: 2481
Quote:
Originally Posted by nimda79
Tried it, still shows all users, instead of the ones who's country belongs in the database jos_emea.
change this --
Code:
LEFT OUTER
  JOIN jos_emea c 
    ON c.country = b.value
to this --
Code:
INNER
  JOIN jos_emea c 
    ON c.country = b.value

Reply With Quote
  #5  
Old November 2nd, 2009, 04:35 PM
nimda79 nimda79 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 9 nimda79 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 8 m 55 sec
Reputation Power: 0
So all the fields that use the b.value go null unless they contain a value from the jos_emea now. on the previous one I tried to add to the where statement "and c.country IS NOT NULL" but that is doing the same as doing the inner join.

Reply With Quote
  #6  
Old November 2nd, 2009, 07:39 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 20,768 r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 1 Week 3 Days 17 h 39 m 41 sec
Reputation Power: 2481
sorry, i guess i don't understand your tables

or, actually, i think i do... the field/value structure is probably an example of EAV (entity-attribute-value) design

sorry, i can't help you with that, it's way too complicated

Reply With Quote
  #7  
Old November 3rd, 2009, 09:29 AM
nimda79 nimda79 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 9 nimda79 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 8 m 55 sec
Reputation Power: 0
Quote:
Originally Posted by r937
sorry, i guess i don't understand your tables

or, actually, i think i do... the field/value structure is probably an example of EAV (entity-attribute-value) design

sorry, i can't help you with that, it's way too complicated


You are correct on the table structure but I have a way around it but I don't know how to interface it into the query.

The easiest way that I have been able to figure out is buy using this:
MAX(IF(b.field_id=12,b.value=c.country,NULL))=1
as a filter but I do not know how to put that in my query. I think it needs to be in a HAVING or WHERE syntax just like the email filter I have, but I am doing something wrong. Sorry I am kinda new to SQL syntax and their uses.

Reply With Quote
  #8  
Old November 5th, 2009, 01:58 PM
nimda79 nimda79 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 9 nimda79 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 8 m 55 sec
Reputation Power: 0
anyone have any ideas?
Comments on this post
cafelatte agrees: Yes, but you're not going to like it :-(

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Having problems converting MS Access Query to mySQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek