Skip to content
Advertisement

Tag: select

Fastest way to determine if record exists

As the title suggests… I’m trying to figure out the fastest way with the least overhead to determine if a record exists in a table or not. Sample query: Say the ? is swapped with ‘TB100’… both the first and second queries will return the exact same result (say… 1 for this conversation). The last query will return ‘TB100’ as

MySQL INSERT INTO … VALUES and SELECT

Is there a way to insert pre-set values and values I get from a select-query? For example: I have the value of “A string” and the number 5, but I’ve to find the [int] value from a select like this: that gives me that id to put inside table1. How to merge this into one statement? Answer Use an insert

SELECT id HAVING maximum count of id

Have a products table with item_id and color_id. I’m trying to get the color_id with the most non-null instances. This fails: with This Returns I am looking for color_id 3, which has the most instances. Is there a quick and easy way of getting what I want without 2 queries? Answer This will give you the color_id and the count

Rename single column in SELECT * in SQL, select all but a column

here is what I’m trying to do- I have a table with lots of columns and want to create a view with one of the column reassigned based on certain combination of values in other columns, e.g. Name, Age, Band, Alive ,,, <too many other fields) And i want a query that will reassign one of the fields, e.g. However,

sql select query in same table

i have a newby sql related question. let’s say i have this simple table: i’d like to query for records which have “counterparts” only, i.e. i want to get a b only if there is b a in the table but i want to skip the “back links” (which is b ahere). to sum up i’d like to get the

Advertisement