0

I cannot figure out how to select multiple columns and a comma separated column.

I have:

Table: example_tbl
| amount   | recurring | frequency    |
| 100      | 150       |  8,monthly   |
| 200      | 250       |  1,annually  |

The problem seems to be with the frequency and the comma. I tried:

$q = mysql_query("SELECT amount, recurring FROM example_tbl WHERE id=".$item['relid']." LIMIT 1" AND * FROM example_tbl WHERE FIND_IN_SET ('monthly', frequency));

Any help would be appreciated.

1
  • What is it you want to select? Commented Oct 4, 2013 at 16:37

1 Answer 1

1

The problem has nothing to do with the comma, your SQL syntax is just wrong. Connect all the conditions in a single WHERE clause using AND.

$q = mysql_query("SELECT amount, recurring, frequency
                  FROM example_tbl
                  WHERE id=".$item['relid']."
                    AND FIND_IN_SET ('monthly', frequency)
                  LIMIT 1");
Sign up to request clarification or add additional context in comments.

2 Comments

Is it valid to specify more than once FIND_IN_SET, like: AND FIND_IN_SET ('monthly', frequency) AND FIND_IN_SET ('annually', frequency)
Sure. They're just expressions, you can use them like any other expression.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.