blob Posted July 31, 2008 Share Posted July 31, 2008 my table 'Answers' is: ----------------- key | value ========== nam | John ----------------- ema | john@aol.com ----------------- age | 44 ----------------- pho | 212 ----------------- web | aol.com ----------------- add | 12 high ----------------- i would like to select 4 values (nam,ema,pho,web) and ignore the other values and place them into array like this info[0] = 'John' info[1] = 'john@aol.com' info[2] = '212' info[3] = 'aol.com' i started with this statement SELECT t1.value FROM Answers t1 WHERE t1.key LIKE 'nam' but how do i add another column? this doesn't seem to work: SELECT t1.value, t2.value FROM Answers t1,t2 WHERE t1.key LIKE 'nam' OR t2.key LIKE 'ema' Quote Link to comment Share on other sites More sharing options...
Xurion Posted July 31, 2008 Share Posted July 31, 2008 Looks like its just one table. SELECT nam, ema, pho, web FROM answers WHERE key LIKE nam Quote Link to comment Share on other sites More sharing options...
blob Posted July 31, 2008 Author Share Posted July 31, 2008 the nam, ema, pho, web are values in the column 'key' so i can't select them directly but changing OR to AND seem to have worked SELECT t1.value, t2.value FROM t1,t2 WHERE t1.key LIKE 'nam' AND t2.key LIKE 'ema' and mixing in id column with another table this worked also SELECT g.id, t1.value, t2.value, t3.value, t4.value FROM g, t1, t2, t3, t4 WHERE g.id = t1.id AND g.id = t2.id AND g.id = t3.id AND g.id = t4.id AND t1.key LIKE 'nam' AND t2.key LIKE 'ema' AND t3.key LIKE 'pho' AND t4.key LIKE 'web' Quote Link to comment Share on other sites More sharing options...
fenway Posted July 31, 2008 Share Posted July 31, 2008 Oh my... please don't do that. Do you want a single record or multiple records? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 31, 2008 Share Posted July 31, 2008 lol ever hear of a join blob? Quote Link to comment Share on other sites More sharing options...
blob Posted July 31, 2008 Author Share Posted July 31, 2008 i think it's obvious i am not familiar with JOIN i am trying to get an array with multiple records, each containing values for 4 matching keys also a very smart person pointed out to me that in my instance i can use = instead of LIKE, as i am matching exact string. so here is my try with JOIN, would this be a correct way of doing select? SELECT g.id, t1.value, t2.value, t3.value, t4.value FROM g JOIN t1 on g.id = t1.id and t1.key = 'nam' JOIN t2 on g.id = t2.id and t2.key = 'ema' JOIN t3 on g.id = t3.id and t3.key = 'pho' JOIN t4 on g.id = t4.id and t4.key = 'web' i appreciate very much your help and time to teach me! Quote Link to comment Share on other sites More sharing options...
fenway Posted August 5, 2008 Share Posted August 5, 2008 I still don't understand what you're trying to achieve... since it's all in the same table, you could get the same result with an OR -- and without 4 joins. Please clarify. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.