Mysql Filter Table with multiple values separated by semicolon
I am trying to filter my table that the where clause has multiple value separated with semicolon. I am trying to use find in set but it does not give any output.
tblAddress:
Address Mat month
tblA X 01
tblA Y 01
tblB Z 01
tblB 1 01
tblC Y 01
tblC J 01
tblD M 01
tblD S 01
tblA X 02
tblA Y 02
tblB Z 02
tblB 1 02
tblC Y 02
tblC J 02
tblD M 02
tblD S 02
I am trying to filter it by month and address
SELECT *
FROM tblAddress
WHERE month BETWEEN "01" AND "02"
AND month BETWEEN "01" AND "02"
AND FIND_IN_SET(Address, REPLACE("tblA;tblC", ';', ',') )
Current Output is no result showing
but my desired output
tblAddress
Address Mat Month
tblA X 01
tblA Y 01
tblC Y 01
tblC J 01
tblA X 02
tblA Y 02
tblC Y 02
tblC J 02
I am wondering if its possible using findinset or wherein? I will really appreciate any advice thank you
CREATE TABLE tblAddress (Address VARCHAR(20), Mat VARCHAR(20),month VARCHAR(20));
mysql
add a comment |
I am trying to filter my table that the where clause has multiple value separated with semicolon. I am trying to use find in set but it does not give any output.
tblAddress:
Address Mat month
tblA X 01
tblA Y 01
tblB Z 01
tblB 1 01
tblC Y 01
tblC J 01
tblD M 01
tblD S 01
tblA X 02
tblA Y 02
tblB Z 02
tblB 1 02
tblC Y 02
tblC J 02
tblD M 02
tblD S 02
I am trying to filter it by month and address
SELECT *
FROM tblAddress
WHERE month BETWEEN "01" AND "02"
AND month BETWEEN "01" AND "02"
AND FIND_IN_SET(Address, REPLACE("tblA;tblC", ';', ',') )
Current Output is no result showing
but my desired output
tblAddress
Address Mat Month
tblA X 01
tblA Y 01
tblC Y 01
tblC J 01
tblA X 02
tblA Y 02
tblC Y 02
tblC J 02
I am wondering if its possible using findinset or wherein? I will really appreciate any advice thank you
CREATE TABLE tblAddress (Address VARCHAR(20), Mat VARCHAR(20),month VARCHAR(20));
mysql
Do you have a SQL Fiddle or DB fiddle setup for this ?
– Madhur Bhaiya
Nov 20 at 12:34
I am sorry I dont have sql fiddle
– aika aika
Nov 20 at 12:41
I've had a go at answering, but I must confess I do not see wheres.Mall
comes from in your query
– Barry
Nov 20 at 14:07
add a comment |
I am trying to filter my table that the where clause has multiple value separated with semicolon. I am trying to use find in set but it does not give any output.
tblAddress:
Address Mat month
tblA X 01
tblA Y 01
tblB Z 01
tblB 1 01
tblC Y 01
tblC J 01
tblD M 01
tblD S 01
tblA X 02
tblA Y 02
tblB Z 02
tblB 1 02
tblC Y 02
tblC J 02
tblD M 02
tblD S 02
I am trying to filter it by month and address
SELECT *
FROM tblAddress
WHERE month BETWEEN "01" AND "02"
AND month BETWEEN "01" AND "02"
AND FIND_IN_SET(Address, REPLACE("tblA;tblC", ';', ',') )
Current Output is no result showing
but my desired output
tblAddress
Address Mat Month
tblA X 01
tblA Y 01
tblC Y 01
tblC J 01
tblA X 02
tblA Y 02
tblC Y 02
tblC J 02
I am wondering if its possible using findinset or wherein? I will really appreciate any advice thank you
CREATE TABLE tblAddress (Address VARCHAR(20), Mat VARCHAR(20),month VARCHAR(20));
mysql
I am trying to filter my table that the where clause has multiple value separated with semicolon. I am trying to use find in set but it does not give any output.
tblAddress:
Address Mat month
tblA X 01
tblA Y 01
tblB Z 01
tblB 1 01
tblC Y 01
tblC J 01
tblD M 01
tblD S 01
tblA X 02
tblA Y 02
tblB Z 02
tblB 1 02
tblC Y 02
tblC J 02
tblD M 02
tblD S 02
I am trying to filter it by month and address
SELECT *
FROM tblAddress
WHERE month BETWEEN "01" AND "02"
AND month BETWEEN "01" AND "02"
AND FIND_IN_SET(Address, REPLACE("tblA;tblC", ';', ',') )
Current Output is no result showing
but my desired output
tblAddress
Address Mat Month
tblA X 01
tblA Y 01
tblC Y 01
tblC J 01
tblA X 02
tblA Y 02
tblC Y 02
tblC J 02
I am wondering if its possible using findinset or wherein? I will really appreciate any advice thank you
CREATE TABLE tblAddress (Address VARCHAR(20), Mat VARCHAR(20),month VARCHAR(20));
mysql
mysql
edited Nov 20 at 15:08
asked Nov 20 at 12:21
aika aika
306
306
Do you have a SQL Fiddle or DB fiddle setup for this ?
– Madhur Bhaiya
Nov 20 at 12:34
I am sorry I dont have sql fiddle
– aika aika
Nov 20 at 12:41
I've had a go at answering, but I must confess I do not see wheres.Mall
comes from in your query
– Barry
Nov 20 at 14:07
add a comment |
Do you have a SQL Fiddle or DB fiddle setup for this ?
– Madhur Bhaiya
Nov 20 at 12:34
I am sorry I dont have sql fiddle
– aika aika
Nov 20 at 12:41
I've had a go at answering, but I must confess I do not see wheres.Mall
comes from in your query
– Barry
Nov 20 at 14:07
Do you have a SQL Fiddle or DB fiddle setup for this ?
– Madhur Bhaiya
Nov 20 at 12:34
Do you have a SQL Fiddle or DB fiddle setup for this ?
– Madhur Bhaiya
Nov 20 at 12:34
I am sorry I dont have sql fiddle
– aika aika
Nov 20 at 12:41
I am sorry I dont have sql fiddle
– aika aika
Nov 20 at 12:41
I've had a go at answering, but I must confess I do not see where
s.Mall
comes from in your query– Barry
Nov 20 at 14:07
I've had a go at answering, but I must confess I do not see where
s.Mall
comes from in your query– Barry
Nov 20 at 14:07
add a comment |
2 Answers
2
active
oldest
votes
This is not a single statement, but this is a pure MySQL solution:
SET @csv_list = REPLACE("tblA;tblC", ';', ',');
SET @expression = CONCAT('SELECT * FROM tblAddress WHERE Month IN (01,02) AND s.Mall IN (', @csv_list, ') ORDER BY Address');
PREPARE myquery FROM @expression;
EXECUTE myquery
The alternative would be to ensure your variable is pre-fixed and post-fixed with the semi-colon, then use something this:
SELECT *
FROM tblAddress
WHERE Month IN (01,02)
AND LOCATE(CONCAT(';', s.Mall, ';'), ";tblA;tblC;" )
ORDER BY Address
thank you very much I really appreciate your time help thank you all your answer is really helpfiul and answered my question with an explanation thank you so much
– aika aika
Nov 20 at 15:11
add a comment |
Try this
SELECT *
FROM tblAddress
WHERE Month IN (01,02)
AND Address IN ('tblA','tblc')
ORDER BY Address;
how does this account for using / converting a string with semi-colon separated values in it?
– Barry
Nov 20 at 14:08
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53392894%2fmysql-filter-table-with-multiple-values-separated-by-semicolon%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is not a single statement, but this is a pure MySQL solution:
SET @csv_list = REPLACE("tblA;tblC", ';', ',');
SET @expression = CONCAT('SELECT * FROM tblAddress WHERE Month IN (01,02) AND s.Mall IN (', @csv_list, ') ORDER BY Address');
PREPARE myquery FROM @expression;
EXECUTE myquery
The alternative would be to ensure your variable is pre-fixed and post-fixed with the semi-colon, then use something this:
SELECT *
FROM tblAddress
WHERE Month IN (01,02)
AND LOCATE(CONCAT(';', s.Mall, ';'), ";tblA;tblC;" )
ORDER BY Address
thank you very much I really appreciate your time help thank you all your answer is really helpfiul and answered my question with an explanation thank you so much
– aika aika
Nov 20 at 15:11
add a comment |
This is not a single statement, but this is a pure MySQL solution:
SET @csv_list = REPLACE("tblA;tblC", ';', ',');
SET @expression = CONCAT('SELECT * FROM tblAddress WHERE Month IN (01,02) AND s.Mall IN (', @csv_list, ') ORDER BY Address');
PREPARE myquery FROM @expression;
EXECUTE myquery
The alternative would be to ensure your variable is pre-fixed and post-fixed with the semi-colon, then use something this:
SELECT *
FROM tblAddress
WHERE Month IN (01,02)
AND LOCATE(CONCAT(';', s.Mall, ';'), ";tblA;tblC;" )
ORDER BY Address
thank you very much I really appreciate your time help thank you all your answer is really helpfiul and answered my question with an explanation thank you so much
– aika aika
Nov 20 at 15:11
add a comment |
This is not a single statement, but this is a pure MySQL solution:
SET @csv_list = REPLACE("tblA;tblC", ';', ',');
SET @expression = CONCAT('SELECT * FROM tblAddress WHERE Month IN (01,02) AND s.Mall IN (', @csv_list, ') ORDER BY Address');
PREPARE myquery FROM @expression;
EXECUTE myquery
The alternative would be to ensure your variable is pre-fixed and post-fixed with the semi-colon, then use something this:
SELECT *
FROM tblAddress
WHERE Month IN (01,02)
AND LOCATE(CONCAT(';', s.Mall, ';'), ";tblA;tblC;" )
ORDER BY Address
This is not a single statement, but this is a pure MySQL solution:
SET @csv_list = REPLACE("tblA;tblC", ';', ',');
SET @expression = CONCAT('SELECT * FROM tblAddress WHERE Month IN (01,02) AND s.Mall IN (', @csv_list, ') ORDER BY Address');
PREPARE myquery FROM @expression;
EXECUTE myquery
The alternative would be to ensure your variable is pre-fixed and post-fixed with the semi-colon, then use something this:
SELECT *
FROM tblAddress
WHERE Month IN (01,02)
AND LOCATE(CONCAT(';', s.Mall, ';'), ";tblA;tblC;" )
ORDER BY Address
edited Nov 20 at 14:22
answered Nov 20 at 14:06
Barry
3,10571637
3,10571637
thank you very much I really appreciate your time help thank you all your answer is really helpfiul and answered my question with an explanation thank you so much
– aika aika
Nov 20 at 15:11
add a comment |
thank you very much I really appreciate your time help thank you all your answer is really helpfiul and answered my question with an explanation thank you so much
– aika aika
Nov 20 at 15:11
thank you very much I really appreciate your time help thank you all your answer is really helpfiul and answered my question with an explanation thank you so much
– aika aika
Nov 20 at 15:11
thank you very much I really appreciate your time help thank you all your answer is really helpfiul and answered my question with an explanation thank you so much
– aika aika
Nov 20 at 15:11
add a comment |
Try this
SELECT *
FROM tblAddress
WHERE Month IN (01,02)
AND Address IN ('tblA','tblc')
ORDER BY Address;
how does this account for using / converting a string with semi-colon separated values in it?
– Barry
Nov 20 at 14:08
add a comment |
Try this
SELECT *
FROM tblAddress
WHERE Month IN (01,02)
AND Address IN ('tblA','tblc')
ORDER BY Address;
how does this account for using / converting a string with semi-colon separated values in it?
– Barry
Nov 20 at 14:08
add a comment |
Try this
SELECT *
FROM tblAddress
WHERE Month IN (01,02)
AND Address IN ('tblA','tblc')
ORDER BY Address;
Try this
SELECT *
FROM tblAddress
WHERE Month IN (01,02)
AND Address IN ('tblA','tblc')
ORDER BY Address;
edited Nov 20 at 13:52
Barry
3,10571637
3,10571637
answered Nov 20 at 12:53
Prashant Deshmukh.....
34917
34917
how does this account for using / converting a string with semi-colon separated values in it?
– Barry
Nov 20 at 14:08
add a comment |
how does this account for using / converting a string with semi-colon separated values in it?
– Barry
Nov 20 at 14:08
how does this account for using / converting a string with semi-colon separated values in it?
– Barry
Nov 20 at 14:08
how does this account for using / converting a string with semi-colon separated values in it?
– Barry
Nov 20 at 14:08
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53392894%2fmysql-filter-table-with-multiple-values-separated-by-semicolon%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Do you have a SQL Fiddle or DB fiddle setup for this ?
– Madhur Bhaiya
Nov 20 at 12:34
I am sorry I dont have sql fiddle
– aika aika
Nov 20 at 12:41
I've had a go at answering, but I must confess I do not see where
s.Mall
comes from in your query– Barry
Nov 20 at 14:07