Selecting a single row in MySQL

后端 未结 3 1251
名媛妹妹
名媛妹妹 2020-12-30 01:03

I am using MySQL, I have a table that has 9 columns. One of them is the primary key.

How can I select a single row, by the primary key or column 8 or 4?

3条回答
  •  庸人自扰
    2020-12-30 01:40

    Columns in SQL don't have a defined 'order'. Database systems generally keep track of an order for display purposes, but it doesn't make sense to ask a database to select a column by number. You need to know the column's name in order to query its contents.

    The same thing goes for the primary key (which, incidentally, may not be just a single column). You have to know which column it is, and what that column is named, in order to execute a query.

    If you don't know these things, or need to figure them out dynamically, then

    DESCRIBE tablename;
    

    will tell you the names of each column, and whether it is part of the primary key or not. It will return a table that you can read, like any other result.

提交回复
热议问题