Jump to content

Help with a union of four tables and using where with the four


2xAA

Recommended Posts

Hello guys,

 

I'm having a problem with this:

$query = "SELECT patch_lsdj_pulse.*, patch_lsdj_wave.*, patch_lsdj_kit.*, patch_lsdj_noise.* FROM patch_lsdj_pulse, patch_lsdj_wave, patch_lsdj_kit, patch_lsdj_noise WHERE pulse_name, wave_name, kit_name, noise_name LIKE \"%$trimmed%\" order by id"

I have four tables:

 

patch_lsdj_pulse

patch_lsdj_wave

patch_lsdj_kit

patch_lsdj_noise

 

which have rows respectively:

 

pulse_name

wave_name

kit_name

noise_name

 

As you can see by the code, I need to select the rows which have the value of $trimmed in from each of the four tables.

The SQL line there can't complete, and I can't find anything which can help me search through the four tables like that :/

 

Thanks in advance,

 

-2xAA

 

Updated, my bad ):

 

$query ="(SELECT patch_lsdj_pulse.* FROM patch_lsdj_pulse WHERE pulse_name LIKE \"%$trimmed%\")
UNION
(SELECT patch_lsdj_wave.* FROM patch_lsdj_wave WHERE wave_name LIKE \"%$trimmed%\")
UNION
(SELECT patch_lsdj_kit.* FROM patch_lsdj_kit WHERE kit_name LIKE \"%$trimmed%\")
UNION
(SELECT patch_lsdj_noise.* FROM patch_lsdj_noise WHERE noise_name LIKE \"%$trimmed%\")
ORDER BY id";

So something like this would be better? (Note, this code still doesn't work)

No worries, sorted it.

In UNIONs, each select must have the same amount of colums/rows. So I've only selected the three I required from each.

(SELECT id, pulse_name, usrname FROM patch_lsdj_pulse)
UNION ALL
(SELECT id, wave_name, usrname FROM patch_lsdj_wave)
UNION ALL
(SELECT id, kit_name, usrname FROM patch_lsdj_kit)
UNION ALL
(SELECT id, noise_name, usrname FROM patch_lsdj_noise)
ORDER BY id;

 

Thanks again fenway :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.