Hello!

A slightly unusual MySQL request is required.

The bottom line is:

We have a table, say, 'table', it has fields: 'id', 'name', 'tag', 'status'.

Task: make a sample of the same 'name' (i.e., let's say if we have name in the database: 'Ivan', 'Alexander', 'Alexander', 'Ivan', then we need the database to be issued either by Ivan Ivan, or Alexander Alexander), you also need to make a condition so that the 'status' field is equal to '1'.

My work:

SELECT * FROM (`table`) WHERE `name` IN (SELECT `name` FROM `table` GROUP BY `name` HAVING count(*)>1) AND `status` = '1' 

But at this request, it gives out both Ivan and Alexander, and I also need to give out only one value.

  • > some one value And to you without a difference what? There are no selection criteria? - Deonis
  • You can by id - what is the first id, then the value will be displayed. But, in general, it does not matter to me. - nick777 pm

1 answer 1

See this option . Only the meaning I do not find, because in this case, the same entry will always be selected. In the example, it is "Alexander".

  • the point is that after the selection and certain operations the status will change, which means the next sample will no longer get the same value again - nick777
  • @ nick777, you know better. PS I slightly corrected the example there and changed the link - Deonis
  • Thank you for the provided option, but there is only one value given out, and I need everyone to give out (i.e., duplicate, that is, 3 rows of 'Alexander' should be issued if you take your table as an example). - nick777
  • one
    As explained, and answered. Watch Now - Deonis
  • Thanks, all worked well. Truth in PhpMyAdmin worked only if you remove LIMIT 1. - nick777