Skip to main content
Inspiring
August 1, 2006
Question

Access > mySQL SQL....

  • August 1, 2006
  • 1 reply
  • 560 views
Hope someone can help with this - I've basically created the following tables / queries as part of my first mySQL project :

Candidates
---------------
Candidate_ID (autonumber)
Name (text)
...

1, Iain
2, Fi
3, Rob


Vacancies
--------------
Vacancy_ID (autonumber)
Vacancy (text)
...

1, Cartographer
2, Gardener
3, Occupational therapist
4, Web designer
5, Recruitment manager


Profiles
-----------
Profile_ID (autonumber)
Profile (text)
...

1, Map making
2, Web design
3, Gardening
4, Hand therapy
5, Recruitment
6, Aviation
7, Sport
8, Travel


VacancyProfiles
----------------------
Vacancy_ID (number)
Profile_ID (number)
...

1,1
1,2
4,2
2,3
3,4
5,5
5,6

CandidateProfiles
--------------------
Candidate_ID (number)
Vacancy_ID (number)
...

1,1
1,2
1,7
1,8
2,3
2,4
2,8
3,5
3,6
3,7

and from there created two queries

CandidatesQuery
--------------------

SELECT Candidates.Candidate_ID, Candidates.Name, Profiles.Profile_ID, Profiles.Profile
FROM Profiles INNER JOIN (Candidates INNER JOIN CandidateProfiles ON Candidates.Candidate_ID = CandidateProfiles.Candidate_ID) ON Profiles.Profile_ID = CandidateProfiles.ProfileID;

1, Iain, 1, Map making
1, Iain, 2, Web design
1, Iain, 7, Sport
1, Iain, 8, Travel
2, Fi, 3, Gardening
2, Fi, 4, Hand therapy
2, Fi, 8, Travel
3, Rob, 5, Recruitment
3, Rob, 6, Aviation
3, Rob, 7, Sport

and

Vacancies_Query
-------------------

SELECT Vacancies.Vacancy_ID, Vacancies.Vacancy, Profiles.Profile_ID, Profiles.Profile
FROM Profiles INNER JOIN (Vacancies INNER JOIN VacancyProfiles ON Vacancies.Vacancy_ID = VacancyProfiles.VacancyID) ON Profiles.Profile_ID = VacancyProfiles.ProfileID;
...

1, Cartographer, 1, Map making
1, Cartographer, 2, Web design
2, Gardener, 3, Gardening
3, Occupational therapist, 4, Hand therapy
4, Web designer, 2, Web design
5, Recruitment manager, 5, Recruitment
5, Recruitment manager, 6, Aviation

Trouble is, I come from an Access background, and I think the syntax of mySQL SQL is different to Access SQL - in the case here for the INNER JOINs - could anyone help out with the syntax for the queries above in mySQL friendly SQL, as I'm a bit unsure of what it should be.

Cheers,
Iain


This topic has been closed for replies.

1 reply

Inspiring
August 1, 2006
Iain71 wrote:
> SELECT Candidates.Candidate_ID, Candidates.Name, Profiles.Profile_ID,
> Profiles.Profile
> FROM Profiles INNER JOIN (Candidates INNER JOIN CandidateProfiles ON
> Candidates.Candidate_ID = CandidateProfiles.Candidate_ID) ON
> Profiles.Profile_ID = CandidateProfiles.ProfileID;

Haven't studied your tables in detail, but this translates to this in
MySQLese:

SELECT Candidates.Candidate_ID, Candidates.Name, Profiles.Profile_ID,
Profiles.Profile
FROM Profiles, Candidates, CandidateProfiles
WHERE Candidates.Candidate_ID = CandidateProfiles.Candidate_ID
AND Profiles.Profile_ID = CandidateProfiles.ProfileID

> SELECT Vacancies.Vacancy_ID, Vacancies.Vacancy, Profiles.Profile_ID,
> Profiles.Profile
> FROM Profiles INNER JOIN (Vacancies INNER JOIN VacancyProfiles ON
> Vacancies.Vacancy_ID = VacancyProfiles.VacancyID) ON Profiles.Profile_ID =
> VacancyProfiles.ProfileID;

SELECT Vacancies.Vacancy_ID, Vacancies.Vacancy, Profiles.Profile_ID,
Profiles.Profile
FROM Profiles, Vacancies, VacancyProfiles
WHERE Vacancies.Vacancy_ID = VacancyProfiles.VacancyID
AND Profiles.Profile_ID = VacancyProfiles.ProfileID

--
David Powers
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "Foundation PHP 5 for Flash" (friends of ED)
http://foundationphp.com/
Inspiring
August 2, 2006
Thanks David - I think I prefer the mySQL version.

I did try it with the INNER JOIN syntax, and have a page here that seems to work - if you click on any vacancy it brings up a detail page with matching 'profiles' :

http://www.searchtechuk.com/database/vacancies2.php

The last trick (for displaying data at least - still not sure about adding/editing records to related tables simultaneously, as I'm used to doing in Access - see other thread!) would be to click on any Vacancy and bring up a list of matching Candidates - would it simply be an amalgam of the above - so something like :

SELECT *
FROM Vacancies, Candidates, CandidateProfiles, VacancyProfiles, Profiles
WHERE Vacancies.VacancyID=VacancyProfiles.VacancyID
AND Profiles.ProfileID=VacancyProfiles.ProfileID
AND Candidates.CandidateID=CandidateProfiles.CandidatesID
AND Profiles.ProfileID=CandidateProfiles.ProfileID

Cheers,
Iain