Sub query in a single SQL field

Asked

Viewed 86 times

0

I need to create a code where I update a field always adding a value to what already exists.

Example table assuming this population is already

CAMPOS: ID | EMAIL | QUEMCURTIU
        1  |[email protected]| 3, 46, 81, 

// below the owner user ID ($id = 36) clicked to like

UPDATE table SET WHO likes = WHO likes + "$id";

 CAMPOS: ID | EMAIL | QUEMCURTIU
         1  |[email protected]| 3, 46, 81, 36  

So far so good , however what would need now was to make a select based on these separate values some idea? What I’m trying is something like

SELECT * FROM TABLE WHERE WHO LIKES NOT LIKE %$id%

but this way if it has the number 14 and 144 of the wrong any idea of UPDATE and SELECT differently is welcome

  • They say the fewer appointments, the better? (performance) following this idea I want to finalize my idea using a single table, my system using 3 tables doing the same function this working, I’m just looking for other means ( I will test the performance of the 2 types sql benchmark)

  • in the case there the ID 36 is that of the user who clicked on to like , the ID 1 is of @dvd another user | if the ID 1 click on Like the ID 36 will be inserted in the field WHO likes it the following -> 1, | if the ID 24 click on Like the ID 36 will be inserted in the field WHO likes it the following -> 1, 24

  • but I’m scrambling with select which searches for text within the field

  • yes this code I wrote there running actually this adding, I am using Concat to enter the ids, as the comma and I was searching to perform the query via a joker

  • yes however that is not the problem . my problem is the issue of SELECT

  • 2

    You’d have to create the pattern: ,3,46,81,36,.. makes it easier to find the value with LIKE '%,$id,%'

  • The "QUEMCURTIU" field would have to have as default value the comma, and you just add the values with the update: UPDATE tabela SET QUEMCURTIU = QUEMCURTIU + '$id,';... the result will be numbers delimited by comma before and after, avoiding the confusion of 14 and 144.

  • which bank is ? you could use an array field as well... or do what the dvd said

  • @Rovannlinhalis mysql , I’m trying to get no more will $sql = "SELECT * FROM usuarios WHERE email <> '$email' AND canaisquejaseinscreveu NOT LIKE ',%%,' ";

Show 4 more comments

1 answer

0

SELECT * FROM TABELA WHERE FIND_IN_SET($id, QUEMCURTIU) = 0

Even if it works, my comment on the question remains valid. If your argument is performance, this is much worse than normalizing the relationship correctly, and is not a standard SQL function.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.