0

I'm attempting to write DBTNG query for a Migrate v2 class (D6), and I can't quite get a WHERE clause using IN to work. Here's the query I need:

select ngeuu.user_name, ngeu.email_address1
from nge_users ngeu inner join nge_user_to_group_tbl ngeutg on ngeu.user_id = ngeutg.user_id
where ngeutg.usergroup_id IN (16, 5608, 48, 34, 22, 26, 24, 18, 28, 20, 14, 12, 6879, 36);

This query returns the appropriate amount of rows. The way I have the query written in my Migrate class is:

$query = db_select('nge_users', 'ngeu');
$query->innerJoin('nge_user_to_group_tbl', 'ngeutg', 'ngeu.user_id=ngeutg.user_id');
$query->fields('ngeu', array('user_name', 'email_address1'))
$query->condition('ngeutg.user_id', array(16, 5608, 48, 34, 22, 26, 24, 18, 28, 20, 14, 12, 6879, 36), 'IN');
$query->duplicate();

but I start getting duplicate rows after 4 records, even though the query by itself doesn't return any. How do I need to change this to make it correct?

Thanks.

2

Your original conditions looks in usergroup_id, while the D7 versions checks user_id?

Also, there is no duplicate() method, only distinct().

You can use something like dpm((string)$query) to debug the generated query, and dpm($query->getArguments) to get the arguments passed to it.

0

Coming back to answer this one after a while. Here's the code I ended up using:

$query = db_select('nge_users', 'ngeu');
$query->innerJoin('nge_user_to_group_tbl', 'ngeutg', 'ngeu.user_id=ngeutg.user_id');
$query->fields('ngeu', array('user_id', 'user_name', 'email_address1', 'first_name', 'last_name'));
$query->condition('ngeutg.usergroup_id', array(16, 5608, 48, 34, 22, 26, 24, 18, 28, 20, 14, 12, 6879, 36), 'IN');
$query->distinct();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.