我的" Android"开发应用程序。
我试图从2个表中检索一些数据,例如:
post ( post_title, post_desc )
postmeta ( postmeta_value )
postmeta_ID是外键。我想从两个表中的帖子ID == 1中检索一些特定的(帖子标题,帖子desc和所有postmeta值)数据。
我已经使用了这种语法,但总是在SELECT":
附近说"错误String q2 = " SELECT post_content, post_title, "
+ "land.postmeta_value landValue, "
+ "price.postmeta_value priceValue, "
+ "bedroom.postmeta_value bedroomValue, "
+ "bathroom.postmeta_value bathroomValue, "
+ "pool.postmeta_value poolValue,"
+ " type.postmeta_value typeValue, "
+ "ownership.postmeta_value ownershipValue, "
+ "location.postmeta_value locationValue, "
+ "poolType.postmeta_value poolTypeValue, "
+ "carPort.postmeta_value carPortValue, "
+ "so.postmeta_value soValue, "
+ "ct.postmeta_value ctValue "
+ "FROM post "
+ "INNER JOIN postmeta land ON post._id=land.postmeta_ID "
+ "INNER JOIN postmeta price ON post._id=price.postmeta_ID "
+ "INNER JOIN postmeta bedroom ON post._id=bedroom.postmeta_ID "
+ "INNER JOIN postmeta bathroom ON post._id=bathroom.postmeta_ID "
+ "INNER JOIN postmeta pool ON post._id=pool.postmeta_ID"
+ "INNER JOIN postmeta type ON post._id=type.postmeta_ID"
+ "INNER JOIN postmeta ownership ON post._id=ownership.postmeta_ID"
+ "INNER JOIN postmeta location ON post._id=location.postmeta_ID"
+ "INNER JOIN postmeta poolType ON post._id=poolType.postmeta_ID "
+ "INNER JOIN postmeta carPort ON post._id=carPort.postmeta_ID"
+ "INNER JOIN postmeta so ON post._id=so.postmeta_ID"
+ "INNER JOIN postmeta ct ON post._id=ct.postmeta_ID WHERE post_ID = 2";
当我只使用3个内连接时,它很好......但是当谈到这一点时,总是说错误。
我的语法有问题吗?或者在语法上使用内连接是否存在最大限制?
我无法附上表格结构截图,因为我没有10个声誉。
答案 0 :(得分:1)
确保SQL字符串的每一行末尾都有空格,否则您最终会发送以下内容:
"INNER JOIN postmeta carPort ON post._id=carPort.postmeta_IDINNER JOIN postmeta so ON post._id=so.postmeta_ID"
到SQL解释器,它可能会吐出来。
答案 1 :(得分:0)
没关系。我使用了这种语法:
SELECT post_title, post_content, postmeta_key, postmeta_value
FROM post INNER JOIN postmeta land ON post._id=land.postmeta_ID
WHERE postmeta_ID = " + postID + " AND postmeta_key IN (
'landSize', 'buildingSize', 'propertyPrice', 'propertyBedroom',
'propertyBathroom', 'pool', 'propertyType', 'propertyOwnership',
'propertyLocation', 'propertyPoolType', 'propertyCarPort',
'propertySpecialOffer', 'propertyCurrencyType'
)