sql - Postgresql - return results if field value exists in another table -


I have the following postgrascape query that selects some fields from the statement field, which is called statement_bank:

  Selection statement_it, Statement_love statement from statement_bank WHERE category_id = 6 and level = 7   

I have another table called the statement_recordus, and the fields for that table are:

  date | User_id | Statement_id   

Once a statement for a particular user_id is used, then statement_id is entered in the statement_records table. This can be recorded a few times for different users.

I'm looking to run the first query so that it can only return from the statement_bank table of statement_id if it exists between the statement_records table between a specific date 01-01-2013 and 01- Between 01-2014

How can I get it?

Thanks

I think you want an existing section . Based on the information you provided, it will look something like this:

  select statement_id, statement_value from statement_bank sr where range_ id = 6 and level = 7 and exist (choose 1 from statement_record sr , Where between sr.user_id = Sb.user_id and sr.statement_id = sb.statement_id and sr.date between '2013-01-01' and '2013-12-31');   

Note: I'm assuming that you do not really want a match for the 2014-01-01, but only by the end of 2013.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -