[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] MySQL, SELECT's og UNION



Okay, dead end!

Havde ellers lige fundet guldægget, men MySQL tillader kun en operand i SELECT IF og SELECT CASE, så det kan ikke gøres i en query.

/Nis

Guldægget, hvis nogle skulle være interesseret:

(

SELECT IF( table1.pretype_id = NULL , (
table1.tid, table1.pretype_id, table1.type_name, table1.type_desc, table1.type_number, table1.type_char
), (
table1.tid, table2.pretype_id, table2.type_name, table2.type_desc, table1.type_number, table1.type_char
) )
FROM table1, table2
WHERE (
table1.type_id =1
)
AND (
table1.users_uid =1
)
ORDER BY table1.type_number
)
UNION (


SELECT NULL , table2.pretype_id, table2.type_name, table2.type_desc, table2.type_number, table2.type_char
FROM table2
WHERE (
table2.type_id =1
)
AND (
table2.pretype_id NOT
IN (
(


SELECT pretype_id
FROM table1
WHERE pretype_id IS NOT NULL
AND type_id =1
AND users_uid =1
)
)
)
ORDER BY table2.type_number
)


Nis wrote:
Burde måske lige tilføje, at jeg skal bruge alle datasæt fra tabel1 og i tilfælde af et pretype_id skal det datasæt der matcher pretype_id fra table2 linkes sammen med tid fra table1. Men alle datasæt fra table2 som ikke er linket ind i table1, skal også med...

Har kastet mig over noget CASE WHEN THEN med en UNION til sidst for at få table2 med...

Og hvorfor spørger nogen. Fordi jeg ellers kommer ud i noget med 3 gange connect + query med tilhørende 3 gange PHP kode!
MySQL er stadig noget hurtigere til at afvikle det end med PHP flettet ind i!


/Nis



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2006-09-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *