catfan / Medoo

The lightweight PHP database framework to accelerate the development.
https://medoo.in
MIT License
4.83k stars 1.15k forks source link

Feature - Union Queries #290

Closed scarstens closed 3 years ago

scarstens commented 8 years ago

We have been using the Medoo library in our API project. However, today, we attempted to build our Union query between two tables and found out... you cannot do this yet in Medoo.

Unions are pretty simple, SELECT union SELECT. Would it not be possible to union 2 Medoo queries fairly easily?

EvandroZanatta commented 8 years ago

:+1:

SyuTingSong commented 8 years ago

Why don't you just query twice and merge two result arrays in PHP?

scarstens commented 8 years ago

Because that would create 2 queries? That's not scalable. That seems like a silly answer. That's like asking why MySQL even bothered to build UNION queries.

SyuTingSong commented 8 years ago

SQL is a database language, providing many syntaxes to fit many different cases. Medoo is only a simple lightweight library to generate some common SQL queries and adapt different RDBMS. I guess the reason we love it is its simple and easy to use.

Complex queries such as sub-clauses, union, procedures and triggers cannot be described gracefully in medoo's way. Using $medoo->query($sql) for complex cases should be a better solution.

scarstens commented 8 years ago

I disagree, Unions are not complex, they are simple. Thats why I wrote Unions are pretty simple, SELECT union SELECT. Would it not be possible to union 2 Medoo queries fairly easily?

Also you are not a contributor, that I can tell, why don't you back off and let a contributor respond.

SyuTingSong commented 8 years ago

Now, $medoo->select method receives 4 parameters is complex enough.

Also you are not a contributor, you tell them what you are expecting for, I tell them what I am worry about.

siswadi commented 7 years ago

$data = $database->query("--complex query--")->fetchAll();

complex query

scarstens commented 7 years ago

Lol what advantage is there of using medoo for this? lol. The whole point of medoo is to allow query generation though PHP OOP. Why can't you take $medoo_query_builder_1 and union $medoo_query_builder_2?

MrMarci666 commented 5 years ago

I'm facing the same problem, and I'm shocked guys. Medoo is a really great and lightweight query builder, but it's kinda sad, that I can't make a union query. I think calling union queries as "complex queries" is a little bit funny tho :)

ante4 commented 4 years ago

This is funny and serious I think you should on integrating union into medoo. What is the point of using a database framework without the necessary things like union and others

drnkwati commented 1 year ago

Why was this issue closed? Is union query now supported? Any example on how unions queries are executed? Thanks