December 1, 201510 yr I have table with some column fields are name studentid and status(yes/no) If i want to find out those records which have same studentid but different status? What should i do?
December 1, 201510 yr select * from table where status = 1 and studentid in (select studentid from table where status = 0)
December 1, 201510 yr ... status(yes/no)... There is no need for a string datatype for your status field (unless you are using Access and the boolean datatype which stores "Yes" or "No" in a string format) For MySQL databases you can use TINYINT(1) to create a boolean type. The field could contain two values then: 0 and 1. (If you allow null you would technically have 3 values) This would optimize your select statement a lot as it takes time for the database to scan string values.
December 2, 201510 yr There is no need for a string datatype for your status field (unless you are using Access and the boolean datatype which stores "Yes" or "No" in a string format) For MySQL databases you can use TINYINT(1) to create a boolean type. The field could contain two values then: 0 and 1. (If you allow null you would technically have 3 values) This would optimize your select statement a lot as it takes time for the database to scan string values. I actually think a more appropriate datatype to use in this case would be ENUM
December 3, 201510 yr I actually think a more appropriate datatype to use in this case would be ENUM Good point. That would keep your database slim and save you from converting the values to strings programmatically
Create an account or sign in to comment