sql - MySql search with two tables, one table for count only -


i'm having trouble mysql query.

the query pulling 2 tables. both tables contain data, want count(*) second table.

select m.*, (select count(*) cd_members_offers mo.mo_member_id = m.m_id) mo_count  cd_members m, cd_members_offers mo  /* these variables , don't exist */ (m.m_fname '%richie%' or m.m_lname '%richie%' or m.m_email '%richie%') , (m.m_signupdate >= 20130807 , m.m_signupdate <= 20130810) , m.m_add_state = 'qld'  , (mo_count >= '2' , mo_count <= '5')  /* end of variables */ , mo.mo_member_id = m.m_id  order m.m_id asc 

the /* quotes */ don't exist in code. wanted show how query potentially if variables entered.

i had issue @ first many duplicates appear. i'm quite confident mo_count >= not correct way it.

i'm still playing code , doing more research, if able save me hours, i'd appreciate it.

it's hard tell sure not seeing tables schema, sample data etc. query might this

select m.*, count(mo_member_id) mo_count    cd_members m left join cd_members_offers mo      on mo.mo_member_id = m.m_id   (m.m_fname '%richie%' or m.m_lname '%richie%' or m.m_email '%richie%')    , m.m_signupdate >= '2013-08-07' , m.m_signupdate <= '2013-08-10'    , m.m_add_state = 'qld'   group m.m_id having mo_count between 0 , 5 

sample output:

 | m_id | m_fname | m_lname |          m_email |                  m_signupdate | m_add_state | mo_count | -------------------------------------------------------------------------------------------------------- |    1 |  richie |  richie |  richie@mail.com | august, 08 2013 00:00:00+0000 |         qld |        3 | |    2 | richie2 | richie2 | richie2@mail.com | august, 09 2013 00:00:00+0000 |         qld |        0 | 

here sqlfiddle demo


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -