0

Ok, I now introduce the problem, I have 3 tables Company, CompanyName, Project. In Company i have many companies id and projects id, in CompanyName names of all companies, in Project have names of all project.

If you not understand i will give example,

  • Company: 1, 3; 5, 7; . . .
  • CompanyName: 1, FirstName; 2 Secondname; 3 Thirdname; . . .
  • Project: 1, Firstproject; 2, SecondProject; . . .

Result must be: Company name - Project name

  • FirstName - Third project
  • FifthName - Seventh project

But I don't know hot to get data from db like in the example Company name - Project name

I never do SQL query with 3 tables.

My bad you not understand the question ;(

See:

  • Table Company have 2 rows (3 but we need only 2): CompanyID and ProjectId
  • Table CompanyName have 2 rows: Id and Name
  • Table Project have 2 rows Id and Name

In Table Company are only numbers for example CompanyID=3 and ProjectId=100

And I dont know, WHEN I HAVE CompanyID=3 and ProjectId=100 get data from CompanyName and Project and answer must be THEcompany3 = TheProject100.

2
  • 2
    Can you do a query with two tables? Or just don't know the syntax for JOIN at all? Commented Jul 11, 2012 at 17:23
  • I cant do, but I dont dont know good algoritm, what do with data select all 3 rows or something else ;( Commented Jul 11, 2012 at 17:25

2 Answers 2

2

I think something like this might work:

SELECT 
    companyName, projectName, companyID
FROM
    company c 
INNER JOIN 
    companyName cn ON c.companyID=cn.companyID
INNER JOIN
    project p ON c.companyID=p.companyID

Editted with new query

SELECT 
    cn.name, p.name
FROM
    company c
INNER JOIN 
    companyName cn ON c.companyID=companyName.ID
INNER JOIN
    project p ON c.companyID=project.ID

Is that what you're after?

Sign up to request clarification or add additional context in comments.

5 Comments

companyName, projectName is now ROW, this is 3 tables companyName, projectName, company.
I've added companyID to the SELECT statement - is that what you mean?
Please look at my first post I edit it, maybe now it will be easier understandable for you ;)
And how is this different from my initial answer ?
@Razvan - aside from having the right field names, I believe it's identical to both our previous answers.
0
Select cn.companyname, p.projectname 
FROM company c, projects p, companyname cn 
WHERE c.id = p.id AND c.id = cn.id

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.