ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Query two tables: exp:query sql

April 19, 2012 1:44pm

Subscribe [3]
  • #1 / Apr 19, 2012 1:44pm

    niallthompson

    17 posts

    I am trying to use a SQL query to return all entries and to also only return entries that have a status of open.

    I can’t seem to get my head around it. Am absolute beginner with EE and SQL.

    This is what I have:

    SELECT field_id_3 FROM exp_channel_data WHERE EXISTS ( SELECT status FROM exp_statuses WHERE status = 'open' );

    Any help appreciated

     

  • #2 / Apr 19, 2012 2:16pm

    boswebdev

    52 posts

    SELECT d.field_id_3
    FROM exp_channel_data d
    INNER JOIN exp_channel_entries t ON t.entry_id = d.entry_id
    WHERE t.status = ‘open’


    should do the trick

  • #3 / Apr 20, 2012 10:38am

    Shane Eckert

    7174 posts

    Hey niallthompson,

    I am glad to see that boswebdev was able to provide some SQL. Not my strongest skill, so always love to see the community jump in with direction in this area.

    Nice work guys.

    Can you test this and see if it works for you? Let us know!

    Cheers,

  • #4 / Apr 20, 2012 10:53am

    niallthompson

    17 posts

    It returned an error actually so used EE tags instead. Kept it simple:

    {exp:channel:entries channel="lettings" status="open" backspace="1"}"{town}",{/exp:channel:entries}
  • #5 / Apr 20, 2012 10:56am

    Shane Eckert

    7174 posts

    Hi niallthompson,

    Sweet! Glad to hear it. Channel Entry Tags I do understand perfectly. 😊

    Have a great weekend!

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases