Jump to content

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


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 :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.