2xAA Posted August 14, 2011 Share Posted August 14, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/244792-help-with-a-union-of-four-tables-and-using-where-with-the-four/ Share on other sites More sharing options...
fenway Posted August 14, 2011 Share Posted August 14, 2011 That's a UNION of 4 tables, not a 4-table join. Quote Link to comment https://forums.phpfreaks.com/topic/244792-help-with-a-union-of-four-tables-and-using-where-with-the-four/#findComment-1257392 Share on other sites More sharing options...
2xAA Posted August 14, 2011 Author Share Posted August 14, 2011 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) Quote Link to comment https://forums.phpfreaks.com/topic/244792-help-with-a-union-of-four-tables-and-using-where-with-the-four/#findComment-1257395 Share on other sites More sharing options...
2xAA Posted August 14, 2011 Author Share Posted August 14, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/244792-help-with-a-union-of-four-tables-and-using-where-with-the-four/#findComment-1257404 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.