H
H
hesy2019-03-18 19:10:35
MySQL
hesy, 2019-03-18 19:10:35

What does this sql query say?

Tell me what the following code says:

$sql = "SELECT
    *
FROM
    history h
WHERE
    h.message = 'Blah-Blah'
AND
    h.context->>'current_user' = '$id'
";

Specifically:
h.context->>'current_user' = '$id' , exactly the sign "->>" what does it mean?
history h - do you need a comma between them or is it meant by the history AS h type?
and what is the letter h in message and context for ?
Does a similar query look correct using the QueryBuilder method?
$queryBuilder->select('*')
                     ->from('history', 't')
                     ->where('h.message = :message');
                     ->andWhere('h.context->>curent_user = :id')
                     ->setParameter('message', 'Blah-Blah')
                     ->setParameter('id', $id)
                     ->execute();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Immortal_pony, 2019-03-18
@hesy

h is an alias to the history table . Needed so that when specifying a column from the table in other parts of the query, do not write the word "history" in its entirety.
No, you lost the quotes and the second "r" in the word "current". It should be like this:
Tell me what the following code says:
Subtract the data of all columns from the "history" table. Search only rows where the value of the "message" field is equal to "Blah-Blah" and the value of the "current_user" parameter of the json object stored in the "context" field is equal to the variable "$id"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question