Android : Retrieving data from multiple rows on same field in SQLITE

on Monday, July 7, 2014


I have a problem in my "Android" development apps.


I tried to retrieve some data from 2 tables eg:



post ( post_title, post_desc )

postmeta ( postmeta_value )


postmeta_ID is the foreign key. I wanted to retrieve some specific ( post title, post desc and all postmeta value ) data from post ID == 1 from both table.


I have used this this syntax but always says "error near 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";


When I used only 3 of inner join, it's fine... But when it comes to this, always says error.


Is there something wrong in my syntax ? Or is there a maximum restriction on using the inner join on a syntax ?


I cannot attach the table structure screenshot since I don't have 10 reputation.


0 comments:

Post a Comment