Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
How to execute this query in laravel. ?
select d1.update_id from ( select update_id, count(update_id)
as ct from updates_tags where tag_id in (67,33,86,55) group by
update_id) as d1 where d1.ct=4
you can use Raw Queries in Laravel
$results = DB::select(SELECT * FROM table WHERE id IN (1,2,3,4) AND );
http://fideloper.com/laravel-raw-queries
You can chain where conditions with eloquent, each chained one is evaluated like an and.
$update = Tag::whereIn('t_id',$tags)->whereIn('u_id',$tags)->where(/*more and conditions you could need*/)->lists('u_id')
Edit: If you need the ones coincident with u_id consider this:
$update = DB::table('tags')
->select('t_id', 'u_id', DB::raw('count(*) as total'))
->whereIn('t_id',$tags)
->where('total','=',count($tags))
->groupBy('u_id')
->lists('u_id');
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have a table with multiple columns starting with one keyword link_. I.E. link_0_10, link_10_20, link_20_30 and so on.
I want to select only columns starting with these link_ keywords. How to do that? I can query by RegEx on the value, but on the columns? I have not been able to.
P.S.: I have no prior idea of how many columns may be present.
just change database name and table name with yours and run this query
SELECT `COLUMN_NAME`
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`='database_name'
AND `TABLE_NAME`='table_name' and COLUMN_NAME like 'link_%'
SELECT *
FROM information_schema.columns
WHERE table_name = 'mytable' and column_name like 'link_%'
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have 2 queries. I want to get MAX date. If I get MAX date my subquery will look like below.
Query 1:
select
tb_format.format
from
tb_format
where
tb_format.id not in
(
select
penyakit.format
from
penyakit
where
penyakit.id_puskesmas =$ id
AND MONTH(penyakit.waktu_upload) = MONTH(CURRENT_DATE)
)
I want to add MAX on this MONTH(penyakit.waktu_upload).
Query 2:
select
tb_format.format
from
tb_format
where
tb_format.id not in
(
select
penyakit.format
from
penyakit
where
penyakit.id_puskesmas =$ id
AND MAX(MONTH(penyakit.waktu_upload)) = MONTH(CURRENT_DATE) -- HERE
)
However, I'm getting an error:
You can't have MAX in a WHERE clause, you can have it in a HAVING clause (this explains the difference a bit more)...
select
penyakit.format
from
penyakit
where
penyakit.id_puskesmas =$ id
group by
penyakit.format
having
MAX(MONTH(penyakit.waktu_upload)) = MONTH(CURRENT_DATE)
There has to be a GROUP BY clause and this gives the basis for what the MAX operates over, the HAVING clause is almost a WHERE clause for the GROUP BY.
Not sure what the $ id is so I've just copied from your original code, but this will need to be corrected.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am using following,
select * , CONCAT_WS( row1.',' , combined_data) AS combined_data from table
Actually i looking the data like
row1 Value , row2 Value , row3 Value, ..
Please help me to resolve my problem
You can try like this..
select * , CONCAT_WS( ',',column_name1,colimn_name2) AS combined_data from table
The syntax for CONCAT_WS is
CONCAT_WS (separator, string1, string2,…)
Which is is used to join two or more strings with a separator.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm looking to see if it is possible to select data from table A with a sort so the order of the data changes.
I then want to make a loop so it will go through each row and add it into table B.
Is this possible.
Use a variable #row_number to store the incremented num for your expected sorting.
SET #row_number = 0;
SELECT (#row_number:=#row_number + 1) AS num, Column1
FROM TableA
ORDER BY Column1
This result can be store in temporary table and based on that you can do loop/insert into the TableB
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Thanks for reading.... still on my way to really getting the hang of php an MySQL queries.
I have a system that queries table entries... I have managed the joining of the 2 tables in my sql query.
Sample:
$sql = mysql_query("select * from table1,table2 where `field_table1` = `field_table2` and `x`= 'x' and y = 'y'")
My question on the validation for this query... The joined field in table1 has to be the same as field in table2. Is an if statement the solution and how would I approach this?
Basically I do not want the query to show the result of the search if field_table1 is not = to field_table2.
Thank you for your assistance.
SELECT *
FROM table1
INNER JOIN table2 ON...
WHERE table1.field != table2.field
That should pretty much take care of it.