You are not logged in.

  • Login

Dear visitor, welcome to Coder Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Friday, January 20th 2012, 4:12pm

Problem mit einer Query

Hallo,

ich habe folgendes Problem. Ich möchste Infos aus mehreren Tabelle auslesen. Dies Funktioniert auch soweit, aber ich habe das Problem, wenn ein User kein Eintrag in der tabelle company_jobtime hat wird nichts mehr ausgegeben.

PHP Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Mitarbeiterinfos auslesen
$companyWorker = mysql_query("
 
SELECT
DISTINCT(b.userName),
b.userID,
b.wbbUserID,
c.companyID,
c.departmentNameShort,
d.rankName,
e.jobTime
FROM
company_user as a,
user_info as b,
company_departments as c,
company_ranks as d,
company_jobtime as e
 
WHERE
a.userID=b.userID AND 
a.departmentID=c.departmentID AND
a.userJobLevel=d.jobLevel AND
c.companyID=d.companyID AND
c.companyID=$getCompanyID AND
e.userID=b.userID AND e.companyID=c.companyID
 
ORDER BY
$getSortField $getSortOrder"
);


Gruß

This post has been edited 2 times, last edit by "stedoo" (Jan 20th 2012, 4:20pm)


2

Friday, January 20th 2012, 4:30pm

wenn du trotzdem andere einträge ausgeben möchtest, dann musst du mit left-/right join arbeiten

3

Friday, January 20th 2012, 4:33pm

aber es gibt doch nicht für jeden User einen Eintrag in company_jobtime

4

Friday, January 20th 2012, 4:35pm

aber es gibt doch nicht für jeden User einen Eintrag in company_jobtime

genau dafür ist auch leftjoin gedacht

schau dir diesen beitrag an: Fage zu LEFT OUTER bz RIGHT OUTER JOIN

5

Friday, January 20th 2012, 4:48pm

Ich steh gearde aufen schlauch. Könnte mir jemand mal ein Beispiel in meine Query machen

6

Friday, January 20th 2012, 5:23pm

Hier ein bsp

PHP Quellcode

1
'SELECT u.*, c.* FROM ' . USERS . ' u RIGHT JOIN ' . ARCADE_CAT . ' c ON (u.user_id = c.user_id)


Wenn zb keine User ID in der Tabelle ARCADE_CAT eingetragen ist gibt er die Arcade Tabelle dennoch aus.

7

Friday, January 20th 2012, 6:19pm

könnte das mal jemand in meine query einbauen. ich versteh das gerade überhaupt nicht :D

8

Friday, January 20th 2012, 6:25pm

könnte das mal jemand in meine query einbauen. ich versteh das gerade überhaupt nicht :D

hast du mein link angesehen, da ist es alles super beispielhaft erklärt

9

Friday, January 20th 2012, 6:29pm

ja hab ich. leider versteh ich das nicht

10

Friday, January 20th 2012, 6:36pm

was genau verstehst du nicht? was ein join ist? wie man tabellen joint? :D

PL/SQL Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
SELECT
*
FROM
company_user AS a,
left join user_info AS b ON a.userID=b.userID
left join company_departments AS c ON a.departmentID=c.departmentID
left join company_ranks AS d ON c.companyID=d.companyID 
left join company_jobtime AS e ON e.companyID=c.companyID AND e.userID=b.userID
WHERE
 c.companyID=$getCompanyID
 
 
ORDER BY
$getSortField $getSortOrder"


ungefähr so

11

Friday, January 20th 2012, 7:33pm

edit: funzt nun. Danke dir

This post has been edited 1 times, last edit by "stedoo" (Jan 20th 2012, 7:48pm)


Social bookmarks