我有两张桌子:
1。) User:name,age,address-id
2。) Address: address-id,street-name,city,state
如何使用JOIN查询获取包含地址的用户列表?
像
SELECT User.name, User.age, Address.street-name, Address.city, Address.state FROM User INNER JOIN Address ON:User.address-id=Address.address-id;
如何在一个查询中从这两个表中获取数据?
答案 0 :(得分:2)
您不能直接执行JOIN查询,因为数据库支持parse.com不是SQL数据库而是NoSQL数据库。
在您的特定情况下,您需要做的就是在用户查询中包含地址:
PFQuery *query = [PFQuery queryWithClassName:@"User"]; // Or [PFUser query] if users are PFUsers
[query whereKey:@"someKey" equalTo:@"someValue"]; // Whatever you need to get a correct list of users
[query includeKey:@"address-id"]; // This includes all related Address objects in the result set
[query findObjects]; // Or preferably findObjectsInBackgroundWithBlock
这假设您的address-id属性是关系或指针。