tags:

views:

12

answers:

1

Hi! I would like to query user information like (first_name, last_name, pic, uid) then join with comments data such as text, time.

first this is my query for comment

SELECT text, time, username, fromid FROM comment WHERE post_id ='123456'

then i need to join this query with user

SELECT first_name, last_name FROM user WHERE **uid='fromid'**

uid from user table can join with fromid from comment table.

how can i do it?

thank

A: 

FQL doesn't support joins:

Unlike SQL, the FQL FROM clause can contain only a single table. You can use the IN keyword in SELECT or WHERE clauses to do subqueries, but the subqueries cannot reference variables in the outer query's scope.

Your best bet would be probably to get all user ids from comment results, compile them into a list and run

SELECT first_name, last_name FROM user WHERE uid in (1,2,3,4,5)

And then manually join users with comments.

If you don't want to compile list of userids manually you can run a slightly more heavy query to get all users from comments:

SELECT first_name, last_name FROM user WHERE uid in (SELECT fromid FROM comment WHERE post_id ='123456')

but you still would need to join users and comments manually.

serg