[Opgelost] 2 query's samen voegen tot 1 query
Ik heb dus 2 query's die ik tot 1 query zou willen
Query 1:
Code (php)
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
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
SELECT
fin1.name AS fin1,
fin2.name AS fin2,
newfin.name AS newfin
FROM
fin_combo
LEFT JOIN
fins AS fin1
ON
fin1.id=fin_combo.fin1
LEFT JOIN
fins AS fin2
ON
fin2.id=fin_combo.fin2
LEFT JOIN
fins AS newfin
ON
newfin.id=fin_combo.newfin
WHERE
fin_combo.fin1='".$_POST['fins1']."'
AND
fin_combo.fin2='".$_POST['fins2']."'
ORDER BY
fin1 ASC,
fin2 ASC
LIMIT 1
fin1.name AS fin1,
fin2.name AS fin2,
newfin.name AS newfin
FROM
fin_combo
LEFT JOIN
fins AS fin1
ON
fin1.id=fin_combo.fin1
LEFT JOIN
fins AS fin2
ON
fin2.id=fin_combo.fin2
LEFT JOIN
fins AS newfin
ON
newfin.id=fin_combo.newfin
WHERE
fin_combo.fin1='".$_POST['fins1']."'
AND
fin_combo.fin2='".$_POST['fins2']."'
ORDER BY
fin1 ASC,
fin2 ASC
LIMIT 1
Query 2:
Code (php)
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
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
SELECT
fish1.name AS fish1,
fish2.name AS fish2,
newfish.name AS newfish
FROM
fish_combo
LEFT JOIN
fishes AS fish1
ON
fish1.id=fish_combo.fish1
LEFT JOIN
fishes AS fish2
ON
fish2.id=fish_combo.fish2
LEFT JOIN
fishes AS newfish
ON
newfish.id=fish_combo.newfish
WHERE
fish_combo.fish1='".$_POST['fishes1']."'
AND
fish_combo.fish2='".$_POST['fishes2']."'
ORDER BY
fish1 ASC,
fish2 ASC
LIMIT 1
fish1.name AS fish1,
fish2.name AS fish2,
newfish.name AS newfish
FROM
fish_combo
LEFT JOIN
fishes AS fish1
ON
fish1.id=fish_combo.fish1
LEFT JOIN
fishes AS fish2
ON
fish2.id=fish_combo.fish2
LEFT JOIN
fishes AS newfish
ON
newfish.id=fish_combo.newfish
WHERE
fish_combo.fish1='".$_POST['fishes1']."'
AND
fish_combo.fish2='".$_POST['fishes2']."'
ORDER BY
fish1 ASC,
fish2 ASC
LIMIT 1
Nu zou ik de query zo willen dat ik dus "fin1 fish1, fin2 fish2, newfin newfish" zou krijgen.
Ik heb wel al het een-en-ander geprobeerd maar ik krijg foutmeldingen. (Vraag me niet meer welke, ik heb er al teveel uitgeprobeerd om nu nog te weten welke fouten)
Gewijzigd op 17/12/2014 13:31:23 door G P
Hoe zijn deze 8 tabellen gerelateerd aan elkaar? Oftewel hoe vind je uitgaand van fin_combo de rijen in fish_combo enze.
$_POST['fin1'], $_POST['fin2'], $_POST['fish1'] en $_POST['fish2']
Tabelen
Gewijzigd op 17/12/2014 12:17:05 door G P
Misschien dat wat voorbeeld data helpt.
Code (php)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
SELECT
fin1.name AS fin1,
fish1.name AS fish1,
fin2.name AS fin2,
fish2.name AS fish2,
newfin.name AS newfin,
newfish.name AS newfish
FROM
fin_combo
LEFT JOIN
fins AS fin1
ON
fin1.id=fin_combo.fin1
LEFT JOIN
fins AS fin2
ON
fin2.id=fin_combo.fin2
LEFT JOIN
fins AS newfin
ON
newfin.id=fin_combo.newfin
LEFT JOIN
fish_combo AS breed
ON
breed.fish1='".$_POST['fishes1']."'
AND
breed.fish2='".$_POST['fishes2']."'
LEFT JOIN
fishes AS fish1
ON
fish1.id=breed.fish1
LEFT JOIN
fishes AS fish2
ON
fish2.id=breed.fish2
LEFT JOIN
fishes AS newfish
ON
newfish.id=breed.newfish
WHERE
fin_combo.fin1='".$_POST['fins1']."'
AND
fin_combo.fin2='".$_POST['fins2']."'
ORDER BY
fin1 ASC,
fish1 ASC,
fin2 ASC,
fish2 ASC,
newfin ASC,
newfish ASC
LIMIT 1
fin1.name AS fin1,
fish1.name AS fish1,
fin2.name AS fin2,
fish2.name AS fish2,
newfin.name AS newfin,
newfish.name AS newfish
FROM
fin_combo
LEFT JOIN
fins AS fin1
ON
fin1.id=fin_combo.fin1
LEFT JOIN
fins AS fin2
ON
fin2.id=fin_combo.fin2
LEFT JOIN
fins AS newfin
ON
newfin.id=fin_combo.newfin
LEFT JOIN
fish_combo AS breed
ON
breed.fish1='".$_POST['fishes1']."'
AND
breed.fish2='".$_POST['fishes2']."'
LEFT JOIN
fishes AS fish1
ON
fish1.id=breed.fish1
LEFT JOIN
fishes AS fish2
ON
fish2.id=breed.fish2
LEFT JOIN
fishes AS newfish
ON
newfish.id=breed.newfish
WHERE
fin_combo.fin1='".$_POST['fins1']."'
AND
fin_combo.fin2='".$_POST['fins2']."'
ORDER BY
fin1 ASC,
fish1 ASC,
fin2 ASC,
fish2 ASC,
newfin ASC,
newfish ASC
LIMIT 1