Jump to content

Query help...please


blackcell

Recommended Posts

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.     

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.