Skip to content
Advertisement

Tag: mysql

How to create relationships in MySQL

In class, we are all ‘studying’ databases, and everyone is using Access. Bored with this, I am trying to do what the rest of the class is doing, but with raw SQL commands with MySQL instead of using Access. I have managed to create databases and tables, but now how do I make a relationship between two tables? If I

How do you OR two LIKE statements?

I have tried the following two statements: SELECT col FROM db.tbl WHERE col (LIKE ‘str1’ OR LIKE ‘str2’) AND col2 = num results in a syntax error SELECT col FROM db.tbl WHERE page LIKE (‘str1’ OR ‘…

Can you use an alias in the WHERE clause in mysql?

I need to use an alias in the WHERE clause, but It keeps telling me that its an unknown column. Is there any way to get around this issue? I need to select records that have a rating higher than x. Rating is calculated as the following alias: Answer You could use a HAVING clause, which can see the aliases,

How to use GROUP BY to concatenate strings in MySQL?

Basically the question is how to get from this: foo_id foo_name 1 A 1 B 2 C to this: foo_id foo_name 1 A B 2 C Answer https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_group-concat From the link above, GROUP_CONCAT: This function returns a string result with the concatenated non-NULL values from a group. It returns NULL if there are no non-NULL values.

Advertisement