By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 741 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

query and subquery in python

P: 38
dear all
i am using postgresql data base....
is it possible to write a subquery in inside the main query in python program....
for example something like this.....

courses = db.query("select course_id, student_id, select course_coordinator from teachers join course on teacher.course_id=course.course_id, start_date from school)"

subquery .....student_id, select course_coordinator from teachers join course on teacher.course_id=course.course_id..... is giving one attribute for main QUERY and it is required.......

will this query work..... if not any suggestion to write subquery.....
Jan 23 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 534
python or not, this is just an interface you're using to communicate with the database.

Write your query and test it with the most simple client: psql.
If it works, then plug it in into your python code.

I am not sure what you are trying to achieve with the sql you posted.
Here's a simple example of query using subquery

Expand|Select|Wrap|Line Numbers
  2. select name, phone from student where student.student_id in
  3. -- run a subquery to get the list of ids for the query
  4. ( select student_id from enrollment where enrollment_date > '2007-01-01' )
Sometimes a subquery can be replaced with a join.

Look at this, it may help you
Jan 24 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.