Obtain values from a table according to values in the same table

sql update column with value from another column in the same table
sql set column value based on another column
sql copy data from one column to another in same table
select and insert into same table sql
insert into select same table mysql
sql update column with value from another table
sql copy records into same table change one field
sql update from select

I have an SQL query which returns the id of some items, EJ:

SELECT * FROM items WHERE CAT_ID = 1

The query can return 1 or N random values, suppose it returns "1, 3, 4".

Then I must make a second query to the same table but applying the values returned by the first query. Taking the values above, the second query would be as follows (I am using WHERE IN):

SELECT * FROM items WHERE CAT_ID IN (1, 3, 4)

My question is, is there any way to perform this process in the same query? Thanks.


Try this.

SELECT * FROM items WHERE CAT_ID IN (SELECT CAT_ID FROM items WHERE {YOUR WHERE CLAUSE LOGIC})

Get rows that have common value from the same table with different , For this, you can use GROUP BY HAVING clause. Let us first create a table −​mysql> create table DemoTable1467 -> ( -> Id int, -> Name  The number of values specified in each list must be the same and the values must be in the same order as the columns in the table. A value for each column in the table must be specified or the column list must explicitly specify the columns for each incoming value. DEFAULT Forces the Database Engine to insert the default value defined for a column.


You can try below

SELECT * FROM items WHERE CAT_ID IN (select CAT_ID  from items)

How can insert into a table using values from the same table in , It doesn't matter if the data comes from the same table or a different one. How do you insert values from a register form into a MySQL table (PHP, How can we get randomly different set of rows or values each time from MySQL table? These basic tables are used to support values in dropDownLists on other grids where users use preset values for certain fields and they also fill in other fields manually. Something like this: Now, I am working on a dynamic report that points to the table where I need to get the actual values and not the references.


You can use subquery and join

select i.* from items i join
 (select CAT_ID from items where --your condition
 ) t
 on i.CAT_ID=t.CAT_ID

Different ways to update rows in a table using SQL progressing, To do a conditional update depending on whether the current value of a column Now what happens if you want to update rows in one table based on the  When data from more than one table in the database is required, a join condition is used. Rows in one table can be joined to rows in another table according to common values existing in corresponding columns, that is, usually primary and foreign key columns. TO display data from two or more related tables, write a simple join condition in


Table Value Constructor (Transact-SQL), The number of values specified in each list must be the same and the values must be in the same order as the columns in the table. A value for  I want to grab a value from a table into two different columns for different values from the same table. Use this query as an example (notice how the select is on the same table aliased as 2 different tables): SELECT a.myVal, b.myVal FROM MyTable a, MyTable b WHERE a.otherVal = 100 AND b.otherVal = 200 AND a.id = b.id


Comparing Successive Rows Within The Same Table in MySQL, In this tutorial, we will show you how to compare successive rows within the same table in MySQL using the self-join technique. A table is a container that stores column-oriented data in variables. Table variables can have different data types and sizes as long as all variables have the same number of rows. Table variables have names, just as the fields of a structure have names. The rows of a table can have names, but row names are not required.


Use Queries to show records based on conditions, In this tutorial, you will learn how to use Query statements in Awesome Table to Explanation: Select all columns and sort the rows by the values in column J The text string you use should be exactly the same as the one entered in your the Query output will either add or subtract 1 file depending on the current month)​. Hi Kawser Have trouble in retrieving information from 3 excel, with 3 same sheet names. In 1 excel – sheet 3 is where formula is to go, reference by name is in column A, sheet 1 is where to retrieve information from, Column A is name, Column B is date, Column C is Distance – so on across 20 columns.