logo
down
shadow

Sorting issues with mySQL JOIN


Sorting issues with mySQL JOIN

By : 其实我是一个演员
Date : November 21 2020, 11:01 PM
around this issue For a few days now, I can't find a solution for this one issue regarding sorting the data from a joined table. , Try query
code :
SELECT IF(guides.restaurant1_id = restaurants.id, 1, 0) as srt ,
  restaurants.name AS name, restaurants.style AS style,
  restaurants.address AS address, guides.date1 AS date1, guides.date2 AS date2
  FROM `guides`
INNER JOIN `restaurants` ON guides.restaurant1_id = restaurants.id or guides.restaurant2_id = restaurants.id 
WHERE guides.userid = 2
order by srt DESC
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {   
  echo 
    $row['name'].'<br>'
    .($row['srt']?$row['date1']:$row['date2']).'<br>'
    .$row['style'].'<br>'    
    .$row['address'].'<hr>'    ;
  }
}
else {
  echo 'No results.';
}


Share : facebook icon twitter icon
JOIN issues on mySql

JOIN issues on mySql


By : egoche
Date : March 29 2020, 07:55 AM
should help you out Two tables, brand_gifts bg, giftcode gc:
code :
   SELECT gc.gift_id
    FROM brand_gifts bg, giftcode gc
   WHERE (
    bg.brand_id =1
    AND gc.gift_id = gc.id    <==
   AND gc.usesleft >0
   )
    LIMIT 0 , 30
   SELECT gc.gift_id
    FROM brand_gifts bg, giftcode gc
   WHERE (
    bg.brand_id =1
    AND gc.gift_id = bg.id    <==
   AND gc.usesleft >0
  )
    LIMIT 0 , 30
Issues with mixed join query in MySQL 5.5 though worked in MySQL 4.1.25

Issues with mixed join query in MySQL 5.5 though worked in MySQL 4.1.25


By : Raja Ayyapusetty
Date : March 29 2020, 07:55 AM
I wish this help you This is a bit confusing so bear with me. , I think what you want to do is best expressed by this query:
code :
select p.id, ps.pid, ps.sid, s.id
from p cross join
     s left join
     ps
     on p.id=ps.pid s and ps.sid=s.id;
Issues with inner join in mysql

Issues with inner join in mysql


By : Jat
Date : March 29 2020, 07:55 AM
this one helps. I want to join output of one query with the second table in mysql: , You are missing the outer SELECT clause:
code :
SELECT D.*, E.health_grade
FROM (
  SELECT A.name, A.address, sum(C.penalty_points) as points
  FROM restaurant A
  JOIN inspection B ON (A.restaurant_id = B.restaurant_id)
  JOIN violation C ON (C.violation_id = B.violation_id)
  GROUP BY A.name
) D
JOIN health_points E ON (D.points = E.points)
MYSQL Statement Issues - INNER JOIN, LEFT JOIN WITH GROUP BY and MAX

MYSQL Statement Issues - INNER JOIN, LEFT JOIN WITH GROUP BY and MAX


By : PrabhKirat Singh
Date : March 29 2020, 07:55 AM
this will help As others have already pointed out, you are aggregating by the p_media_user_id column but then selecting other non aggregate columns. This either won't run at all, or it will run but give non determistic results. However, it looks like you just want the most recent record from the p_media table, for each p_media_user_id. If so, then this would seem to be the query you intended to run:
code :
SELECT
    pm1.timestamp, pm1.id, pm1.p_media_user_id, pm1.p_media_type, pm1.p_media_file,
    pm1.wall_post, pm1.p_media_location, pm1.p_media_location_name, 
    pm1.p_media_category, pa.p_source_alert_id, pa.post_id, pa.p_target_alert_id,
    pu.fb_id, pu.username, pu.city, pu.sex, pu.main_image 
FROM p_media as pm1
INNER JOIN
(
    SELECT p_media_user_id, MAX(timestamp) AS max_timestamp
    FROM p_media
    GROUP BY p_media_user_id
) pm2
    ON pm1.p_media_user_id = pm2.p_media_user_id AND
       pm1.timestamp = pm2.max_timestamp
INNER JOIN p_users AS pu
    ON pm1.p_media_user_id = pu.fb_id 
LEFT JOIN p_alerts AS pa
    ON pm1.id = pa.post_id AND
       pa.p_source_alert_id = '3849084';
SQL count(*) issues with join on multiple tables in mysql involving an outer join

SQL count(*) issues with join on multiple tables in mysql involving an outer join


By : ozan cin
Date : March 29 2020, 07:55 AM
it fixes the issue I have three tables, lets say t1, t2, t3 with columns as , Try this query:
code :
SELECT t2.c4, t1.c2, COUNT(t3.c6) 
FROM t1
INNER JOIN t2 ON t1.c1 = t2.c1
LEFT JOIN t3 ON t3.c4 = t2.c4
WHERE t2.c5 = '11'
GROUP BY t2.c4, t1.c2
c4  c2  count
-------------
1   11111   2
2   11111   0
3   22222   0
SELECT t2.c4, t1.c2, COUNT(t3.c6) as count
FROM t1
INNER JOIN t2 ON t1.c1 = t2.c1
LEFT JOIN t3 ON t3.c4 = t2.c4
WHERE t2.c5 = '12'
GROUP BY t2.c4, t1.c2
c4  c2      count
-----------------
4   22222   0
5   33333   1
6   22222   0
Related Posts Related Posts :
  • Event broadcating: Laravel Echo fails receiving broadcasts
  • Chrome extension to execute php file
  • PHP update password form not working
  • Behat stopped working SSL error fwrite() laravel
  • If Statements in print to loop new <li>
  • PHP cafile below version 5.6
  • Selecting by two parameters from table
  • Laravel 5.3 Route::get() returns error Class [classname] does not exist
  • simple_array handling with SonataAdminBundle
  • Codeigniter Email Confirmations
  • Why is it i can't display image? i been trying so many different codes but the image still doesn't display
  • Variadic Variables by Reference
  • php :select column in array with Undefined index error
  • Missing composer/zend command: development-enable
  • how to load array response from ajax into array input textbox
  • Reorder WordPress Plugin echo Order On Posts
  • Want to take backup of code in PHP where files which are to be taken as backup is read from another specified (patch)fol
  • MySQL output in PHP tables
  • line 5: Call to undefined function link_to_route()
  • Sql request with php : select posts where there is a youtube link
  • ZF2 - how to use require_once as $this->render?
  • How to run unit testing in cakephp3?
  • Odd behaviour of array_diff
  • CakePHP Virtual Fields send headers?
  • mySQL in server Terminal, need to see output
  • How to get a single data from comma separated array and displaying data of that record using codeigniter php
  • SELECTING Multiple Rows with an Array and then INSERT to another statement
  • Cron and SetTimeZone in PHP file
  • arrays and index php
  • Yii2 - trasitive dependency in active records
  • Is it possible with docker to run more than one app on port 80 on the same computer?
  • How to work with stripe in laravel 5.2
  • Append <figure> tag at the starting and ending of <img> tag in PHP
  • Autofill form data after login
  • php artisan not returning anything
  • array_intersect_key with three array in php
  • PHP / mySQL - prepare and bind locally
  • how to display controller array values in mvc concept?
  • While loop without explicit increment / counter (basic)
  • updated values are displaying only after refreshing the page
  • PHP: update on DB if i pass it through get url
  • Select * from table where columns contain a keyword
  • Wildcard to route to a controller
  • Unknown component ID: authClientCollection
  • make standings table soccer league
  • Laravel pusher error: JSON returned from webapp was invalid, yet status code was 200
  • How to get most downloads records
  • What argument does my function need to echo get_results() query results
  • Laravel - Toggle value in database with checkbox and ajax
  • $_POST is not working in web services?
  • How to Count the number of objects in elequont Object inside a group by in a already queried collection?
  • how to add custom column in db table when using 'into outfile' query
  • cant load more than 100 words in json android from sql
  • PHP: How to order array by a value of child array
  • composer dump-autoload not working on controller Laravel 5
  • How select random column value from Mysql database using PHP
  • Showing data with specific parameter in Wordpress Query
  • Why die with connect_error() is not working?
  • PHP foreach for child of multidimentional array?
  • how to load another page when clicking a button in another page and pass values to the loaded page in jquery?
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com