Hey all, I am up against a big problem with trying to figure out how to go about this query I am needing.

I need to only display the companies that the user has in their account and also only display the company if they are on the calendar for that day.

My userinfo database is this (only showing needed table info):

```
ID | UserID     | idNumber  | theAccount
----------------------------------------
2  | 5556120012 | NA        | MAIN
6  | 5556120012 | 5680012   | SUB

```

The Company database is this (only showing needed table info):

```
ID | idNumber   | theDateStart | theDateEnd
-------------------------------------------
2  | 5680012    | 2010-06-02   | 2010-06-03
6  | 56057477   | 2010-06-01   | 2010-06-03

```

The SQL Query I have right now works fine at picking the dates that are today for each company.

```
SELECT clientinfo.id, clientinfo.theCompName, clientinfo.theURL, 
clientinfo.picURL, clientinfo.theOwnerFN, clientinfo.theOwnerLN, 
clientinfo.storeNum, clientinfo.compAddress, clientinfo.compAddressC, 
clientinfo.compAddressS, clientinfo.compAddressZ, clientinfo.accountStats,
clientinfo.idNumber, IFNULL(clientoffers.idNumber, 'NA'), 
IFNULL(clientoffers.theDateStart, 'NA'), IFNULL(clientoffers.theDateEnd, 'NA')
FROM clientinfo 
LEFT JOIN clientoffers ON (clientinfo.idNumber = clientoffers.idNumber AND '2010-06-03' 
BETWEEN clientoffers.theDateStart AND clientoffers.theDateEnd), userinfo 
WHERE clientinfo.accountStats = 'OPEN' 
AND IFNULL(clientoffers.idNumber, 'NA') <> "NA" 
GROUP BY clientinfo.idNumber 
ORDER BY clientinfo.theCompName ASC

```

That shows all that have current things on the calendar for each company. Where the problem comes into play is I don't know where to add the userinfo in that query to make sure that user has a company in their account (in order to see stuff on the calendar, the user has to add the company to their account).

So, as the example says above, the user only has company 5680012 in their account so therefore, only that company needs to be displayed in the query. If they had more than one then it should display that many.

On the userinfo db, the column "idNumber" is each company's id number. So in the example above, there is only one company in that user's account (the first one is just a general "MAIN" account not associated with any company.)

As you can see, it's a pretty hard query (at least for me) so I am hoping someone can help me out with it!

David