blackcell Posted December 2, 2011 Share Posted December 2, 2011 I am sorry for a less than adequate description on the subject line. I have two tables. These two tables both have identical fields linking them. Well there is much more but I am only concerned with this much so far. table1 ---------------------- | field1 | field2 | ---------------------- table2 ---------------------- | field1 | field2 | ---------------------- Table 1 will have one record with multiple records existing in table 2 that uniquely key to it from identical field1 and field2 values. So something like: Table1.record1 Table2.record1 Table2.record2 Table3.record3 Table4.record4 Table5.record5 Table6.record6 Table1.record2 Table2.record1 Table2.record2 Table3.record3 Table4.record4 Table5.record5 Table6.record6 Table1.record3 Table2.record1 Table2.record2 Table3.record3 Table4.record4 Table5.record5 Table6.record6 Again, the indented records are linked to the field1 and field2 matching values in both tables. I am sorry if this is a horrible explanation. This is the first time I have ever needed help with mySql. Before this, I was taught to handle this kind of thing with multiple queries in nested loops within PHP(which I now realize is asinine) and I am trying to unlearn the bad and intake the good. Quote Link to comment https://forums.phpfreaks.com/topic/252313-query-helpplease/ Share on other sites More sharing options...
mikosiko Posted December 2, 2011 Share Posted December 2, 2011 .... Table 1 will have one record with multiple records existing in table 2... Huh?... what?.... posting your real tables description (the relevant part) and some data and your expected output should help to those that could try to help you Quote Link to comment https://forums.phpfreaks.com/topic/252313-query-helpplease/#findComment-1293480 Share on other sites More sharing options...
blackcell Posted December 2, 2011 Author Share Posted December 2, 2011 Well, I suppose I should understand that I think the previous description is clear because I work within the data on a daily basis. Because I did not provide you with simple explanation... Tables: vsws_basic vsws_objects Fields I am concerned with basic_part <-Belongs to vsws_basic basic_task <-Belongs to vsws_basic object_part <-Belongs to vsws_objects object_task <-Belongs to vsws_objects I want to do a count of the number of objects with the same part and task as a vsws_basic record with corresponding part and task. So yes, a where clause will need to go in. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/252313-query-helpplease/#findComment-1293489 Share on other sites More sharing options...
blackcell Posted December 2, 2011 Author Share Posted December 2, 2011 Huh?... what?.... posting your real tables description (the relevant part) and some data and your expected output should help to those that could try to help you Huh? I think the ...help to those that... threw me off. If you have anything more to say than a simple, "Could you post some real table names and a little data with expected output?" Then forget this thread I DO NOT want your help. I have few people who condescend in my daily routine and quite frankly want no more of them. I don't care if you are a SQL wizard, you just pissed me off, it will affect the rest of my day, and thanks. I'll wait on another person with more patience than you. Perhaps I am taking this completely out of context, if so let me know. Next step...crayons. Edit: Oh check out: http://dev.mysql.com/doc/refman/5.0/en/join.html I am pretty sure they use generic names and they seem to be successful...go figure right? I don't understand because I have no idea which kind of join to use, or perhaps I am not smart enough to figure it out. Quote Link to comment https://forums.phpfreaks.com/topic/252313-query-helpplease/#findComment-1293494 Share on other sites More sharing options...
blackcell Posted December 2, 2011 Author Share Posted December 2, 2011 I think I found it: SELECT * FROM vsws_objects INNER JOIN vsws_basic ON object_part = basic_part AND object_task = basic_task WHERE basic_comment LIKE '%criteria%' Apologies but I am edgy right now because my boss has taught me the lazy way of doing this(taking care of it with multiple nested loops in PHP) for years and I didn't know any better. Now I am 2 years of experience down on proper query writing because of that. Please understand the frustration. Quote Link to comment https://forums.phpfreaks.com/topic/252313-query-helpplease/#findComment-1293501 Share on other sites More sharing options...
mikosiko Posted December 2, 2011 Share Posted December 2, 2011 ... Perhaps I am taking this completely out of context, if so let me know. ... Yes you did... but is ok.. I do understand your frustration... been there many times myself. good to know that you found the solution Quote Link to comment https://forums.phpfreaks.com/topic/252313-query-helpplease/#findComment-1293512 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.