简体   繁体   English

表中的MySQL SELECT,其中row =(选择val1,val2,val3等)

[英]MySQL SELECT from table where row = (SELECT val1, val2, val3, … etc.)

I'd like to check if row exists, but without telling the column names, but only its values. 我想检查行是否存在,但不告诉列名,而只告诉它值。 IE. IE浏览器

+------+------+------+
|field1|field2|field3|
+------+------+------+
| abc  | cba  |  val |
+------+------+------+

SELECT * FROM myTable WHERE ... = (SELECT 'abc', 'cba', 'val')

Is it possible? 可能吗?

I'm writing a function in php and I'd like to add a row if such row doesn't exist. 我正在用php写一个函数,如果这种行不存在,我想添加一行。 Function would take n parameters, ie. 函数将采用n参数,即。

addNewRowIfDoesNotExist('table1', 'abc', 'cba', 'val');

I don't want to modify the singature of function, but i need to check if such row exist in table as told. 我不想修改功能的单一性,但是我需要检查表中是否存在这样的行。 So I'm not passing column names. 所以我没有传递列名。 So how can i check does row exist without telling the col names? 因此,如何在不告知列名的情况下检查行是否存在?

Thanks 谢谢
Mike 麦克风

Thank you for comments. 感谢您的评论。 I've found it on the internet. 我已经在网上找到了。

check if two "select"s are equivalent 检查两个“选择”是否等效
http://www.mysqltutorial.org/mysql-minus/ http://www.mysqltutorial.org/mysql-minus/

Thanks. 谢谢。
Mike 麦克风

If you would like to see what I mean, there you go: 如果您想了解我的意思,请前往:

function insertRecordIntoTableIfNotExist()
{
    if (func_num_args() < 2)
        exit("Too few arguments at insertRecordIntoTableIfNotExist()<br>");

    $str = changeTableIntoStringWithCommasAndQuotes(func_get_args());
    $firstComma = strpos($str, ",");

    $tableName = substr($str, 0, $firstComma);
    $tableName = substr($tableName, 1, strlen($tableName) - 2);
    $rest = substr($str, $firstComma + 1);

    $result = executeQuery("SELECT " . $rest . " MINUS SELECT * FROM " . $tableName . "_v;");

    if ($result != FALSE)
        if (hasRows($result))
            return;

    if (executeQuery("INSERT INTO " . $tableName . " VALUES(NULL, " . $rest . ");") == FALSE)
    {
        printWrongQuery();

        exit("Error while inserting at insertRecordIntoTableIfNotExist()<br>");
    }
}

You need to specify a new View before you run this function. 在运行此功能之前,您需要指定一个新的视图。 My tables has at first place id , so in view, I don't take it. 我的表格起初有id ,所以看来,我不接受它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何循环访问数组中的PHP值,例如[“ val1”,“ val2”,“ val3”] - How to access PHP values in array like [“val1”,“val2”,“val3”] in loop 从模式中的字符串获取数组-key1:val1,val2,..; key2:val1, - Get array from string in pattern - key1:val1,val2,..;key2:val1, 获取JSON键/值,并使用值(val1,val2,...)更新列(key1,key2,...)的SQL表 - Getting JSON keys/values, and updating SQL table at columns (key1, key2, …) with values (val1, val2, …) 如何为 html 属性 value = "val1, val2" 输入多个值? - How can I enter multiple values for the html attribute value = "val1, val2"? 选择其中一栏为“ val”,然后为“ aaa”,然后为“ ccc”的条目 - Select entries where one column is “val”, then “aaa”, then “ccc” MySQL查询:WHERE $ val(3)IN $ table(2,6,3,8,9)。 如何进行查询 - MySQL Query: WHERE $val(3) IN $table(2,6,3,8,9). How to make that query MySQL选择许多表,每个表的结果都是它自己的键/值对 - MySQL select many tables, each table's results being it's own key/val pair 选择val后,可动态js显示模式 - Dynatable js show modal after select val Laravel视图传递的值未捕获未定义的变量:val1 - Laravel view passed value not capturing Undefined variable: val1 取得URL并添加/?var0 = val0&var1 = val1,而无需离开页面且没有用户输入 - Taking a URL and adding /?var0=val0&var1=val1 with out leaving the page and no user input
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM