Question:
MySQL check for multiple rows with same value without outside language?
Shrander
2012-11-26 01:07:19 UTC
Working on an assignment where the main goal is to restructure a messy table into a batch of cleaner tables. To ensure that the splitting worked, we were given descriptions for queries we were to perform, but an issue I am having is how to:

List the contents of multiple rows if and only if the value in column x is found in any other row in the same column.
It cannot output the row if there aren't more rows where the value in column x matches.


I figure it would be easier with subqueries or something. Easiest way I can think of would be doing something like:
SELECT * FROM table_name WHERE 1 > (SELECT count(*) from table_name where subquery.column_x = parent_query.columnx)

So, similar to a nested loop.
But, I have no clue how to have a subquery reference the parent query.

A solution for the main problem, whether it is similar to my idea or not would be appreciated.
Three answers:
AnalProgrammer
2012-11-26 02:47:10 UTC
You are close.

Try

SELECT * FROM table_name parent_query WHERE 1 < (SELECT count(*) from table_name subquery where subquery.column_x = parent_query.columnx)



Have fun.
anonymous
2017-02-26 15:39:59 UTC
you desire an "IFERROR" fact to return a sparkling cellular if no "confident" exists. In different words, keep your unique forumla, in spite of if, till now the formulation, enter: =IFERROR(your formulation),"") The double quotations on the tip will return a "sparkling" value. in case you desire to instruct something diifferent, type it between the quotations. case in point: =IFERROR(your formulation),"SHAZAM") So....for each cellular that would have decrease back a value of #N/A, you will see "SHAZAM" instead. make constructive to repeat/paste particular over the column to guard the values in case any sorting or manipulating is performed after your formulation has been entered wisely.
?
2012-11-26 01:09:43 UTC
Better to place to ask this question: http://stackoverflow.com/


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...