2

I want to write a self join query, However I dunno how to write it in drupal 7 using db_select().

The query will look like this

SELECT * FROM msg where sender = receiver

Both sender and receiver fields are part of the msg table.

1
  • 1
    we can achieve it using the following query. db_select('msg') ->fields('msg') ->where('sender = receiver'); Commented Mar 17, 2012 at 11:19

2 Answers 2

4

A query using db_select is a lot slower than a 'vanilla' db_query call...for a query as simple as the one you're doing just run it through db_query:

$query = db_query('SELECT * FROM msg where sender = receiver');
0

Its possible with the following query,

db_select('msg')
  ->fields('msg')
  ->where('sender = receiver');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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